Give Xed a Sublime-like searchbar
The search dialog is replaced with a searchbar similar to the one used in Sublime. The following features are implicit and therefore removed: - "incremental search" - "remove highlights" - "parse \n characters" Code style is applied to impacted files (should have been done in a separate commit but it was being discussed during WIP and the new committed code followed neither the new style nor the old).
This commit is contained in:
parent
c8f0c14add
commit
f4236351ae
|
@ -9,8 +9,6 @@ xed/dialogs/xed-encodings-dialog.c
|
|||
[type: gettext/glade]xed/dialogs/xed-encodings-dialog.ui
|
||||
xed/dialogs/xed-preferences-dialog.c
|
||||
[type: gettext/glade]xed/dialogs/xed-preferences-dialog.ui
|
||||
xed/dialogs/xed-search-dialog.c
|
||||
[type: gettext/glade]xed/dialogs/xed-search-dialog.ui
|
||||
xed/xed.c
|
||||
xed/xed-app.c
|
||||
xed/xed-commands-file.c
|
||||
|
@ -34,8 +32,10 @@ xed/xed-plugins-engine.c
|
|||
xed/xed-prefs-manager.c
|
||||
xed/xed-print-job.c
|
||||
[type: gettext/glade]xed/xed-print-preferences.ui
|
||||
[type: gettext/glade]xed/xed-searchbar.ui
|
||||
xed/xed-print-preview.c
|
||||
xed/xed-smart-charset-converter.c
|
||||
xed/xed-searchbar.c
|
||||
xed/xed-statusbar.c
|
||||
xed/xed-style-scheme-manager.c
|
||||
xed/xed-tab.c
|
||||
|
|
245
po/xed.pot
245
po/xed.pot
|
@ -8,7 +8,7 @@ msgid ""
|
|||
msgstr ""
|
||||
"Project-Id-Version: PACKAGE VERSION\n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2016-08-18 20:07+0100\n"
|
||||
"POT-Creation-Date: 2016-09-20 16:32+0100\n"
|
||||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
||||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
||||
"Language-Team: LANGUAGE <LL@li.org>\n"
|
||||
|
@ -637,7 +637,7 @@ msgstr ""
|
|||
msgid "Line Numbers"
|
||||
msgstr ""
|
||||
|
||||
#: ../xed/dialogs/xed-preferences-dialog.ui.h:7 ../xed/xed-view.c:1959
|
||||
#: ../xed/dialogs/xed-preferences-dialog.ui.h:7 ../xed/xed-view.c:1011
|
||||
msgid "_Display line numbers"
|
||||
msgstr ""
|
||||
|
||||
|
@ -741,55 +741,6 @@ msgstr ""
|
|||
msgid "Plugins"
|
||||
msgstr ""
|
||||
|
||||
#: ../xed/dialogs/xed-search-dialog.c:302
|
||||
#: ../xed/dialogs/xed-search-dialog.ui.h:1 ../xed/xed-window.c:1449
|
||||
msgid "Replace"
|
||||
msgstr ""
|
||||
|
||||
#: ../xed/dialogs/xed-search-dialog.c:313 ../xed/xed-window.c:1447
|
||||
msgid "Find"
|
||||
msgstr ""
|
||||
|
||||
#: ../xed/dialogs/xed-search-dialog.c:417
|
||||
msgid "Replace _All"
|
||||
msgstr ""
|
||||
|
||||
#: ../xed/dialogs/xed-search-dialog.c:418 ../xed/xed-commands-file.c:589
|
||||
msgid "_Replace"
|
||||
msgstr ""
|
||||
|
||||
#: ../xed/dialogs/xed-search-dialog.ui.h:2
|
||||
msgid "Replace All"
|
||||
msgstr ""
|
||||
|
||||
#: ../xed/dialogs/xed-search-dialog.ui.h:3
|
||||
msgid "_Search for: "
|
||||
msgstr ""
|
||||
|
||||
#: ../xed/dialogs/xed-search-dialog.ui.h:4
|
||||
msgid "Replace _with: "
|
||||
msgstr ""
|
||||
|
||||
#: ../xed/dialogs/xed-search-dialog.ui.h:5
|
||||
msgid "_Match case"
|
||||
msgstr ""
|
||||
|
||||
#: ../xed/dialogs/xed-search-dialog.ui.h:6
|
||||
msgid "Match _entire word only"
|
||||
msgstr ""
|
||||
|
||||
#: ../xed/dialogs/xed-search-dialog.ui.h:7
|
||||
msgid "Search _backwards"
|
||||
msgstr ""
|
||||
|
||||
#: ../xed/dialogs/xed-search-dialog.ui.h:8
|
||||
msgid "_Wrap around"
|
||||
msgstr ""
|
||||
|
||||
#: ../xed/dialogs/xed-search-dialog.ui.h:9
|
||||
msgid "_Parse escape sequences (e.g. \\n)"
|
||||
msgstr ""
|
||||
|
||||
#: ../xed/xed.c:104
|
||||
msgid "Show the application's version"
|
||||
msgstr ""
|
||||
|
@ -863,6 +814,10 @@ msgstr ""
|
|||
msgid "Do you want to try to replace it with the one you are saving?"
|
||||
msgstr ""
|
||||
|
||||
#: ../xed/xed-commands-file.c:589
|
||||
msgid "_Replace"
|
||||
msgstr ""
|
||||
|
||||
#: ../xed/xed-commands-file.c:650 ../xed/xed-commands-file.c:873
|
||||
#, c-format
|
||||
msgid "Saving file '%s'…"
|
||||
|
@ -950,35 +905,17 @@ msgstr ""
|
|||
msgid "A small and lightweight text editor"
|
||||
msgstr ""
|
||||
|
||||
#: ../xed/xed-commands-search.c:112
|
||||
#, c-format
|
||||
msgid "Found and replaced %d occurrence"
|
||||
msgid_plural "Found and replaced %d occurrences"
|
||||
msgstr[0] ""
|
||||
msgstr[1] ""
|
||||
|
||||
#: ../xed/xed-commands-search.c:122
|
||||
msgid "Found and replaced one occurrence"
|
||||
msgstr ""
|
||||
|
||||
#. Translators: %s is replaced by the text
|
||||
#. entered by the user in the search box
|
||||
#: ../xed/xed-commands-search.c:143
|
||||
#, c-format
|
||||
msgid "\"%s\" not found"
|
||||
msgstr ""
|
||||
|
||||
#: ../xed/xed-document.c:1082 ../xed/xed-document.c:1102
|
||||
#, c-format
|
||||
msgid "Unsaved Document %d"
|
||||
msgstr ""
|
||||
|
||||
#: ../xed/xed-documents-panel.c:97 ../xed/xed-documents-panel.c:111
|
||||
#: ../xed/xed-window.c:2172 ../xed/xed-window.c:2177
|
||||
#: ../xed/xed-window.c:1747 ../xed/xed-window.c:1750
|
||||
msgid "Read-Only"
|
||||
msgstr ""
|
||||
|
||||
#: ../xed/xed-documents-panel.c:784 ../xed/xed-window.c:3531
|
||||
#: ../xed/xed-documents-panel.c:784 ../xed/xed-window.c:2792
|
||||
msgid "Documents"
|
||||
msgstr ""
|
||||
|
||||
|
@ -1548,6 +1485,42 @@ msgstr ""
|
|||
msgid "_Restore Default Fonts"
|
||||
msgstr ""
|
||||
|
||||
#: ../xed/xed-searchbar.ui.h:1
|
||||
msgid "Replace All"
|
||||
msgstr ""
|
||||
|
||||
#: ../xed/xed-searchbar.ui.h:2 ../xed/xed-window.c:1139
|
||||
msgid "Replace"
|
||||
msgstr ""
|
||||
|
||||
#: ../xed/xed-searchbar.ui.h:3
|
||||
msgid "_Search for: "
|
||||
msgstr ""
|
||||
|
||||
#: ../xed/xed-searchbar.ui.h:4
|
||||
msgid "Replace _with: "
|
||||
msgstr ""
|
||||
|
||||
#: ../xed/xed-searchbar.ui.h:5 ../xed/xed-window.c:1137
|
||||
msgid "Find"
|
||||
msgstr ""
|
||||
|
||||
#: ../xed/xed-searchbar.ui.h:6
|
||||
msgid "Find Prev"
|
||||
msgstr ""
|
||||
|
||||
#: ../xed/xed-searchbar.ui.h:7
|
||||
msgid "Case sensitive"
|
||||
msgstr ""
|
||||
|
||||
#: ../xed/xed-searchbar.ui.h:8
|
||||
msgid "Whole word"
|
||||
msgstr ""
|
||||
|
||||
#: ../xed/xed-searchbar.ui.h:9
|
||||
msgid "Wrap"
|
||||
msgstr ""
|
||||
|
||||
#: ../xed/xed-print-preview.c:564
|
||||
msgid "Show the previous page"
|
||||
msgstr ""
|
||||
|
@ -1618,6 +1591,22 @@ msgstr ""
|
|||
msgid "It is not possible to detect the encoding automatically"
|
||||
msgstr ""
|
||||
|
||||
#: ../xed/xed-searchbar.c:70
|
||||
#, c-format
|
||||
msgid "Found and replaced %d occurrence"
|
||||
msgid_plural "Found and replaced %d occurrences"
|
||||
msgstr[0] ""
|
||||
msgstr[1] ""
|
||||
|
||||
#: ../xed/xed-searchbar.c:80
|
||||
msgid "Found and replaced one occurrence"
|
||||
msgstr ""
|
||||
|
||||
#: ../xed/xed-searchbar.c:98
|
||||
#, c-format
|
||||
msgid "\"%s\" not found"
|
||||
msgstr ""
|
||||
|
||||
#: ../xed/xed-statusbar.c:70 ../xed/xed-statusbar.c:76
|
||||
msgid "OVR"
|
||||
msgstr ""
|
||||
|
@ -1758,7 +1747,7 @@ msgstr ""
|
|||
msgid "_Open..."
|
||||
msgstr ""
|
||||
|
||||
#: ../xed/xed-ui.h:59 ../xed/xed-window.c:1377
|
||||
#: ../xed/xed-ui.h:59 ../xed/xed-window.c:1084
|
||||
msgid "Open a file"
|
||||
msgstr ""
|
||||
|
||||
|
@ -1891,111 +1880,95 @@ msgid "Search for and replace text"
|
|||
msgstr ""
|
||||
|
||||
#: ../xed/xed-ui.h:119
|
||||
msgid "_Clear Highlight"
|
||||
msgstr ""
|
||||
|
||||
#: ../xed/xed-ui.h:120
|
||||
msgid "Clear highlighting of search matches"
|
||||
msgstr ""
|
||||
|
||||
#: ../xed/xed-ui.h:121
|
||||
msgid "Go to _Line..."
|
||||
msgstr ""
|
||||
|
||||
#: ../xed/xed-ui.h:122
|
||||
#: ../xed/xed-ui.h:120
|
||||
msgid "Go to a specific line"
|
||||
msgstr ""
|
||||
|
||||
#: ../xed/xed-ui.h:123
|
||||
msgid "_Incremental Search..."
|
||||
msgstr ""
|
||||
|
||||
#: ../xed/xed-ui.h:124
|
||||
msgid "Incrementally search for text"
|
||||
msgstr ""
|
||||
|
||||
#. Documents menu
|
||||
#: ../xed/xed-ui.h:127
|
||||
#: ../xed/xed-ui.h:123
|
||||
msgid "_Save All"
|
||||
msgstr ""
|
||||
|
||||
#: ../xed/xed-ui.h:128
|
||||
#: ../xed/xed-ui.h:124
|
||||
msgid "Save all open files"
|
||||
msgstr ""
|
||||
|
||||
#: ../xed/xed-ui.h:129
|
||||
#: ../xed/xed-ui.h:125
|
||||
msgid "_Close All"
|
||||
msgstr ""
|
||||
|
||||
#: ../xed/xed-ui.h:130
|
||||
#: ../xed/xed-ui.h:126
|
||||
msgid "Close all open files"
|
||||
msgstr ""
|
||||
|
||||
#: ../xed/xed-ui.h:131
|
||||
#: ../xed/xed-ui.h:127
|
||||
msgid "_Previous Document"
|
||||
msgstr ""
|
||||
|
||||
#: ../xed/xed-ui.h:132
|
||||
#: ../xed/xed-ui.h:128
|
||||
msgid "Activate previous document"
|
||||
msgstr ""
|
||||
|
||||
#: ../xed/xed-ui.h:133
|
||||
#: ../xed/xed-ui.h:129
|
||||
msgid "_Next Document"
|
||||
msgstr ""
|
||||
|
||||
#: ../xed/xed-ui.h:134
|
||||
#: ../xed/xed-ui.h:130
|
||||
msgid "Activate next document"
|
||||
msgstr ""
|
||||
|
||||
#: ../xed/xed-ui.h:135
|
||||
#: ../xed/xed-ui.h:131
|
||||
msgid "_Move to New Window"
|
||||
msgstr ""
|
||||
|
||||
#: ../xed/xed-ui.h:136
|
||||
#: ../xed/xed-ui.h:132
|
||||
msgid "Move the current document to a new window"
|
||||
msgstr ""
|
||||
|
||||
#: ../xed/xed-ui.h:143
|
||||
#: ../xed/xed-ui.h:139
|
||||
msgid "Close the current file"
|
||||
msgstr ""
|
||||
|
||||
#: ../xed/xed-ui.h:150
|
||||
#: ../xed/xed-ui.h:146
|
||||
msgid "Quit the program"
|
||||
msgstr ""
|
||||
|
||||
#: ../xed/xed-ui.h:155
|
||||
#: ../xed/xed-ui.h:151
|
||||
msgid "_Toolbar"
|
||||
msgstr ""
|
||||
|
||||
#: ../xed/xed-ui.h:156
|
||||
#: ../xed/xed-ui.h:152
|
||||
msgid "Show or hide the toolbar in the current window"
|
||||
msgstr ""
|
||||
|
||||
#: ../xed/xed-ui.h:158
|
||||
#: ../xed/xed-ui.h:154
|
||||
msgid "_Statusbar"
|
||||
msgstr ""
|
||||
|
||||
#: ../xed/xed-ui.h:159
|
||||
#: ../xed/xed-ui.h:155
|
||||
msgid "Show or hide the statusbar in the current window"
|
||||
msgstr ""
|
||||
|
||||
#: ../xed/xed-ui.h:162
|
||||
#: ../xed/xed-ui.h:158
|
||||
msgid "Edit text in fullscreen"
|
||||
msgstr ""
|
||||
|
||||
#: ../xed/xed-ui.h:169
|
||||
#: ../xed/xed-ui.h:165
|
||||
msgid "Side _Pane"
|
||||
msgstr ""
|
||||
|
||||
#: ../xed/xed-ui.h:170
|
||||
#: ../xed/xed-ui.h:166
|
||||
msgid "Show or hide the side pane in the current window"
|
||||
msgstr ""
|
||||
|
||||
#: ../xed/xed-ui.h:172
|
||||
#: ../xed/xed-ui.h:168
|
||||
msgid "_Bottom Pane"
|
||||
msgstr ""
|
||||
|
||||
#: ../xed/xed-ui.h:173
|
||||
#: ../xed/xed-ui.h:169
|
||||
msgid "Show or hide the bottom pane in the current window"
|
||||
msgstr ""
|
||||
|
||||
|
@ -2019,37 +1992,11 @@ msgstr ""
|
|||
msgid "/ on %s"
|
||||
msgstr ""
|
||||
|
||||
#. create "Wrap Around" menu item.
|
||||
#: ../xed/xed-view.c:1197
|
||||
msgid "_Wrap Around"
|
||||
msgstr ""
|
||||
|
||||
#. create "Match Entire Word Only" menu item.
|
||||
#: ../xed/xed-view.c:1207
|
||||
msgid "Match _Entire Word Only"
|
||||
msgstr ""
|
||||
|
||||
#. create "Match Case" menu item.
|
||||
#: ../xed/xed-view.c:1217
|
||||
msgid "_Match Case"
|
||||
msgstr ""
|
||||
|
||||
#. create "Parse escapes" menu item.
|
||||
#: ../xed/xed-view.c:1227
|
||||
msgid ""
|
||||
"_Parse escape sequences (e.g. \n"
|
||||
")"
|
||||
msgstr ""
|
||||
|
||||
#: ../xed/xed-view.c:1341
|
||||
msgid "String you want to search for"
|
||||
msgstr ""
|
||||
|
||||
#: ../xed/xed-view.c:1350
|
||||
#: ../xed/xed-view.c:672
|
||||
msgid "Line you want to move the cursor to"
|
||||
msgstr ""
|
||||
|
||||
#: ../xed/xed-window.c:930
|
||||
#: ../xed/xed-window.c:719
|
||||
#, c-format
|
||||
msgid "Use %s highlight mode"
|
||||
msgstr ""
|
||||
|
@ -2057,51 +2004,51 @@ msgstr ""
|
|||
#. add the "Plain Text" item before all the others
|
||||
#. Translators: "Plain Text" means that no highlight mode is selected in the
|
||||
#. * "View->Highlight Mode" submenu and so syntax highlighting is disabled
|
||||
#: ../xed/xed-window.c:987 ../xed/xed-window.c:1877
|
||||
#: ../xed/xed-window.c:759 ../xed/xed-window.c:1500
|
||||
msgid "Plain Text"
|
||||
msgstr ""
|
||||
|
||||
#: ../xed/xed-window.c:988
|
||||
#: ../xed/xed-window.c:759
|
||||
msgid "Disable syntax highlighting"
|
||||
msgstr ""
|
||||
|
||||
#. Translators: %s is a URI
|
||||
#: ../xed/xed-window.c:1274
|
||||
#: ../xed/xed-window.c:1003
|
||||
#, c-format
|
||||
msgid "Open '%s'"
|
||||
msgstr ""
|
||||
|
||||
#: ../xed/xed-window.c:1379
|
||||
#: ../xed/xed-window.c:1085
|
||||
msgid "Open a recently used file"
|
||||
msgstr ""
|
||||
|
||||
#: ../xed/xed-window.c:1385
|
||||
#: ../xed/xed-window.c:1088
|
||||
msgid "Open"
|
||||
msgstr ""
|
||||
|
||||
#: ../xed/xed-window.c:1443
|
||||
#: ../xed/xed-window.c:1133
|
||||
msgid "Save"
|
||||
msgstr ""
|
||||
|
||||
#: ../xed/xed-window.c:1445
|
||||
#: ../xed/xed-window.c:1135
|
||||
msgid "Print"
|
||||
msgstr ""
|
||||
|
||||
#. Translators: %s is a URI
|
||||
#: ../xed/xed-window.c:1602
|
||||
#: ../xed/xed-window.c:1249
|
||||
#, c-format
|
||||
msgid "Activate '%s'"
|
||||
msgstr ""
|
||||
|
||||
#: ../xed/xed-window.c:1855
|
||||
#: ../xed/xed-window.c:1481
|
||||
msgid "Use Spaces"
|
||||
msgstr ""
|
||||
|
||||
#: ../xed/xed-window.c:1926
|
||||
#: ../xed/xed-window.c:1538
|
||||
msgid "Tab Width"
|
||||
msgstr ""
|
||||
|
||||
#: ../xed/xed-window.c:3812
|
||||
#: ../xed/xed-window.c:2985
|
||||
msgid "Elevated Privileges"
|
||||
msgstr ""
|
||||
|
||||
|
|
|
@ -86,6 +86,7 @@ INST_H_FILES = \
|
|||
xed-prefs-manager-app.h \
|
||||
xed-prefs-manager.h \
|
||||
xed-progress-message-area.h \
|
||||
xed-searchbar.h \
|
||||
xed-statusbar.h \
|
||||
xed-status-combo-box.h \
|
||||
xed-tab.h \
|
||||
|
@ -152,6 +153,7 @@ libxed_la_SOURCES = \
|
|||
xed-progress-message-area.c \
|
||||
xed-session.c \
|
||||
xed-smart-charset-converter.c \
|
||||
xed-searchbar.c \
|
||||
xed-statusbar.c \
|
||||
xed-status-combo-box.c \
|
||||
xed-style-scheme-manager.c \
|
||||
|
@ -184,6 +186,7 @@ xed-marshal.c: xed-marshal.list $(GLIB_GENMARSHAL)
|
|||
uidir = $(datadir)/xed/ui/
|
||||
ui_DATA = \
|
||||
xed-ui.xml \
|
||||
xed-searchbar.ui \
|
||||
xed-print-preferences.ui
|
||||
|
||||
EXTRA_DIST = \
|
||||
|
|
|
@ -17,14 +17,11 @@ libdialogs_la_SOURCES = \
|
|||
xed-close-confirmation-dialog.c \
|
||||
xed-close-confirmation-dialog.h \
|
||||
xed-encodings-dialog.c \
|
||||
xed-encodings-dialog.h \
|
||||
xed-search-dialog.h \
|
||||
xed-search-dialog.c
|
||||
xed-encodings-dialog.h
|
||||
|
||||
ui_DATA = \
|
||||
xed-encodings-dialog.ui \
|
||||
xed-preferences-dialog.ui \
|
||||
xed-search-dialog.ui
|
||||
xed-preferences-dialog.ui
|
||||
|
||||
EXTRA_DIST = $(ui_DATA)
|
||||
|
||||
|
|
|
@ -1,654 +0,0 @@
|
|||
/*
|
||||
* xed-search-dialog.c
|
||||
* This file is part of xed
|
||||
*
|
||||
* Copyright (C) 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 of the License, 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., 51 Franklin St, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Modified by the xed Team, 2005. See the AUTHORS file for a
|
||||
* list of people on the xed Team.
|
||||
* See the ChangeLog files for a list of changes.
|
||||
*
|
||||
* $Id$
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
#include <glib/gi18n.h>
|
||||
#include <gtk/gtk.h>
|
||||
#include <gdk/gdkkeysyms.h>
|
||||
|
||||
#include "xed-search-dialog.h"
|
||||
#include "xed-history-entry.h"
|
||||
#include "xed-utils.h"
|
||||
#include "xed-marshal.h"
|
||||
#include "xed-dirs.h"
|
||||
|
||||
#define XED_SEARCH_DIALOG_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), \
|
||||
XED_TYPE_SEARCH_DIALOG, \
|
||||
XedSearchDialogPrivate))
|
||||
|
||||
/* Signals */
|
||||
enum
|
||||
{
|
||||
SHOW_REPLACE,
|
||||
LAST_SIGNAL
|
||||
};
|
||||
|
||||
static guint dialog_signals [LAST_SIGNAL] = { 0 };
|
||||
|
||||
struct _XedSearchDialogPrivate
|
||||
{
|
||||
gboolean show_replace;
|
||||
|
||||
GtkWidget *table;
|
||||
GtkWidget *search_label;
|
||||
GtkWidget *search_entry;
|
||||
GtkWidget *search_text_entry;
|
||||
GtkWidget *replace_label;
|
||||
GtkWidget *replace_entry;
|
||||
GtkWidget *replace_text_entry;
|
||||
GtkWidget *match_case_checkbutton;
|
||||
GtkWidget *entire_word_checkbutton;
|
||||
GtkWidget *backwards_checkbutton;
|
||||
GtkWidget *wrap_around_checkbutton;
|
||||
GtkWidget *parse_escapes_checkbutton;
|
||||
GtkWidget *find_button;
|
||||
GtkWidget *replace_button;
|
||||
GtkWidget *replace_all_button;
|
||||
|
||||
gboolean ui_error;
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE(XedSearchDialog, xed_search_dialog, GTK_TYPE_DIALOG)
|
||||
|
||||
enum
|
||||
{
|
||||
PROP_0,
|
||||
PROP_SHOW_REPLACE
|
||||
};
|
||||
|
||||
static void
|
||||
xed_search_dialog_set_property (GObject *object,
|
||||
guint prop_id,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
XedSearchDialog *dlg = XED_SEARCH_DIALOG (object);
|
||||
|
||||
switch (prop_id)
|
||||
{
|
||||
case PROP_SHOW_REPLACE:
|
||||
xed_search_dialog_set_show_replace (dlg,
|
||||
g_value_get_boolean (value));
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
xed_search_dialog_get_property (GObject *object,
|
||||
guint prop_id,
|
||||
GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
XedSearchDialog *dlg = XED_SEARCH_DIALOG (object);
|
||||
|
||||
switch (prop_id)
|
||||
{
|
||||
case PROP_SHOW_REPLACE:
|
||||
g_value_set_boolean (value, dlg->priv->show_replace);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
xed_search_dialog_present_with_time (XedSearchDialog *dialog,
|
||||
guint32 timestamp)
|
||||
{
|
||||
g_return_if_fail (XED_SEARCH_DIALOG (dialog));
|
||||
|
||||
gtk_window_present_with_time (GTK_WINDOW (dialog), timestamp);
|
||||
|
||||
gtk_widget_grab_focus (dialog->priv->search_text_entry);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
show_replace (XedSearchDialog *dlg)
|
||||
{
|
||||
xed_search_dialog_set_show_replace (dlg, TRUE);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
xed_search_dialog_class_init (XedSearchDialogClass *klass)
|
||||
{
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
||||
GtkBindingSet *binding_set;
|
||||
|
||||
object_class->set_property = xed_search_dialog_set_property;
|
||||
object_class->get_property = xed_search_dialog_get_property;
|
||||
|
||||
klass->show_replace = show_replace;
|
||||
|
||||
dialog_signals[SHOW_REPLACE] =
|
||||
g_signal_new ("show_replace",
|
||||
G_TYPE_FROM_CLASS (object_class),
|
||||
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
|
||||
G_STRUCT_OFFSET (XedSearchDialogClass, show_replace),
|
||||
NULL, NULL,
|
||||
xed_marshal_BOOLEAN__NONE,
|
||||
G_TYPE_BOOLEAN, 0);
|
||||
|
||||
g_object_class_install_property (object_class, PROP_SHOW_REPLACE,
|
||||
g_param_spec_boolean ("show-replace",
|
||||
"Show Replace",
|
||||
"Whether the dialog is used for Search&Replace",
|
||||
FALSE,
|
||||
G_PARAM_READWRITE));
|
||||
|
||||
g_type_class_add_private (object_class, sizeof (XedSearchDialogPrivate));
|
||||
|
||||
binding_set = gtk_binding_set_by_class (klass);
|
||||
|
||||
/* Note: we cannot use the keyval/modifier associated with the
|
||||
* GTK_STOCK_FIND_AND_REPLACE stock item since MATE HIG suggests Ctrl+h
|
||||
* for Replace while gtk+ uses Ctrl+r */
|
||||
gtk_binding_entry_add_signal (binding_set, GDK_KEY_h, GDK_CONTROL_MASK, "show_replace", 0);
|
||||
gtk_binding_entry_add_signal (binding_set, GDK_KEY_H, GDK_CONTROL_MASK, "show_replace", 0);
|
||||
}
|
||||
|
||||
static void
|
||||
insert_text_handler (GtkEditable *editable,
|
||||
const gchar *text,
|
||||
gint length,
|
||||
gint *position,
|
||||
gpointer data)
|
||||
{
|
||||
static gboolean insert_text = FALSE;
|
||||
gchar *escaped_text;
|
||||
gint new_len;
|
||||
|
||||
/* To avoid recursive behavior */
|
||||
if (insert_text)
|
||||
return;
|
||||
|
||||
escaped_text = xed_utils_escape_search_text (text);
|
||||
|
||||
new_len = strlen (escaped_text);
|
||||
|
||||
if (new_len == length)
|
||||
{
|
||||
g_free (escaped_text);
|
||||
return;
|
||||
}
|
||||
|
||||
insert_text = TRUE;
|
||||
|
||||
g_signal_stop_emission_by_name (editable, "insert_text");
|
||||
|
||||
gtk_editable_insert_text (editable, escaped_text, new_len, position);
|
||||
|
||||
insert_text = FALSE;
|
||||
|
||||
g_free (escaped_text);
|
||||
}
|
||||
|
||||
static void
|
||||
search_text_entry_changed (GtkEditable *editable,
|
||||
XedSearchDialog *dialog)
|
||||
{
|
||||
const gchar *search_string;
|
||||
|
||||
search_string = gtk_entry_get_text (GTK_ENTRY (editable));
|
||||
g_return_if_fail (search_string != NULL);
|
||||
|
||||
if (*search_string != '\0')
|
||||
{
|
||||
gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog),
|
||||
XED_SEARCH_DIALOG_FIND_RESPONSE, TRUE);
|
||||
gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog),
|
||||
XED_SEARCH_DIALOG_REPLACE_ALL_RESPONSE, TRUE);
|
||||
}
|
||||
else
|
||||
{
|
||||
gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog),
|
||||
XED_SEARCH_DIALOG_FIND_RESPONSE, FALSE);
|
||||
gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog),
|
||||
XED_SEARCH_DIALOG_REPLACE_RESPONSE, FALSE);
|
||||
gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog),
|
||||
XED_SEARCH_DIALOG_REPLACE_ALL_RESPONSE, FALSE);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
response_handler (XedSearchDialog *dialog,
|
||||
gint response_id,
|
||||
gpointer data)
|
||||
{
|
||||
const gchar *str;
|
||||
|
||||
switch (response_id)
|
||||
{
|
||||
case XED_SEARCH_DIALOG_REPLACE_RESPONSE:
|
||||
case XED_SEARCH_DIALOG_REPLACE_ALL_RESPONSE:
|
||||
str = gtk_entry_get_text (GTK_ENTRY (dialog->priv->replace_text_entry));
|
||||
if (*str != '\0')
|
||||
{
|
||||
gchar *text;
|
||||
|
||||
text = xed_utils_unescape_search_text (str);
|
||||
xed_history_entry_prepend_text
|
||||
(XED_HISTORY_ENTRY (dialog->priv->replace_entry),
|
||||
text);
|
||||
|
||||
g_free (text);
|
||||
}
|
||||
/* fall through, so that we also save the find entry */
|
||||
case XED_SEARCH_DIALOG_FIND_RESPONSE:
|
||||
str = gtk_entry_get_text (GTK_ENTRY (dialog->priv->search_text_entry));
|
||||
if (*str != '\0')
|
||||
{
|
||||
gchar *text;
|
||||
|
||||
text = xed_utils_unescape_search_text (str);
|
||||
xed_history_entry_prepend_text
|
||||
(XED_HISTORY_ENTRY (dialog->priv->search_entry),
|
||||
text);
|
||||
|
||||
g_free (text);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
show_replace_widgets (XedSearchDialog *dlg,
|
||||
gboolean show_replace)
|
||||
{
|
||||
if (show_replace)
|
||||
{
|
||||
gtk_widget_show (dlg->priv->replace_label);
|
||||
gtk_widget_show (dlg->priv->replace_entry);
|
||||
gtk_widget_show (dlg->priv->replace_all_button);
|
||||
gtk_widget_show (dlg->priv->replace_button);
|
||||
|
||||
gtk_table_set_row_spacings (GTK_TABLE (dlg->priv->table), 12);
|
||||
|
||||
gtk_window_set_title (GTK_WINDOW (dlg), _("Replace"));
|
||||
}
|
||||
else
|
||||
{
|
||||
gtk_widget_hide (dlg->priv->replace_label);
|
||||
gtk_widget_hide (dlg->priv->replace_entry);
|
||||
gtk_widget_hide (dlg->priv->replace_all_button);
|
||||
gtk_widget_hide (dlg->priv->replace_button);
|
||||
|
||||
gtk_table_set_row_spacings (GTK_TABLE (dlg->priv->table), 0);
|
||||
|
||||
gtk_window_set_title (GTK_WINDOW (dlg), _("Find"));
|
||||
}
|
||||
|
||||
gtk_widget_show (dlg->priv->find_button);
|
||||
}
|
||||
|
||||
static void
|
||||
xed_search_dialog_init (XedSearchDialog *dlg)
|
||||
{
|
||||
GtkWidget *content;
|
||||
GtkWidget *error_widget;
|
||||
gboolean ret;
|
||||
gchar *file;
|
||||
gchar *root_objects[] = {
|
||||
"search_dialog_content",
|
||||
NULL
|
||||
};
|
||||
|
||||
dlg->priv = XED_SEARCH_DIALOG_GET_PRIVATE (dlg);
|
||||
|
||||
gtk_window_set_resizable (GTK_WINDOW (dlg), FALSE);
|
||||
gtk_window_set_destroy_with_parent (GTK_WINDOW (dlg), TRUE);
|
||||
|
||||
gtk_dialog_add_buttons (GTK_DIALOG (dlg),
|
||||
GTK_STOCK_CLOSE, GTK_RESPONSE_CANCEL,
|
||||
NULL);
|
||||
|
||||
/* HIG defaults */
|
||||
gtk_container_set_border_width (GTK_CONTAINER (dlg), 5);
|
||||
gtk_box_set_spacing (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dlg))),
|
||||
2); /* 2 * 5 + 2 = 12 */
|
||||
gtk_container_set_border_width (GTK_CONTAINER (gtk_dialog_get_action_area (GTK_DIALOG (dlg))),
|
||||
5);
|
||||
gtk_box_set_spacing (GTK_BOX (gtk_dialog_get_action_area (GTK_DIALOG (dlg))),
|
||||
6);
|
||||
|
||||
file = xed_dirs_get_ui_file ("xed-search-dialog.ui");
|
||||
ret = xed_utils_get_ui_objects (file,
|
||||
root_objects,
|
||||
&error_widget,
|
||||
"search_dialog_content", &content,
|
||||
"table", &dlg->priv->table,
|
||||
"search_label", &dlg->priv->search_label,
|
||||
"replace_with_label", &dlg->priv->replace_label,
|
||||
"match_case_checkbutton", &dlg->priv->match_case_checkbutton,
|
||||
"entire_word_checkbutton", &dlg->priv->entire_word_checkbutton,
|
||||
"search_backwards_checkbutton", &dlg->priv->backwards_checkbutton,
|
||||
"wrap_around_checkbutton", &dlg->priv->wrap_around_checkbutton,
|
||||
"parse_escapes_checkbutton", &dlg->priv->parse_escapes_checkbutton,
|
||||
NULL);
|
||||
g_free (file);
|
||||
|
||||
if (!ret)
|
||||
{
|
||||
gtk_widget_show (error_widget);
|
||||
|
||||
gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dlg))),
|
||||
error_widget,
|
||||
TRUE, TRUE, 0);
|
||||
gtk_container_set_border_width (GTK_CONTAINER (error_widget),
|
||||
5);
|
||||
|
||||
dlg->priv->ui_error = TRUE;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
dlg->priv->search_entry = xed_history_entry_new ("history-search-for",
|
||||
TRUE);
|
||||
gtk_widget_set_size_request (dlg->priv->search_entry, 300, -1);
|
||||
xed_history_entry_set_escape_func
|
||||
(XED_HISTORY_ENTRY (dlg->priv->search_entry),
|
||||
(XedHistoryEntryEscapeFunc) xed_utils_escape_search_text);
|
||||
|
||||
dlg->priv->search_text_entry = xed_history_entry_get_entry
|
||||
(XED_HISTORY_ENTRY (dlg->priv->search_entry));
|
||||
gtk_entry_set_activates_default (GTK_ENTRY (dlg->priv->search_text_entry),
|
||||
TRUE);
|
||||
gtk_widget_show (dlg->priv->search_entry);
|
||||
gtk_table_attach_defaults (GTK_TABLE (dlg->priv->table),
|
||||
dlg->priv->search_entry,
|
||||
1, 2, 0, 1);
|
||||
|
||||
dlg->priv->replace_entry = xed_history_entry_new ("history-replace-with",
|
||||
TRUE);
|
||||
xed_history_entry_set_escape_func
|
||||
(XED_HISTORY_ENTRY (dlg->priv->replace_entry),
|
||||
(XedHistoryEntryEscapeFunc) xed_utils_escape_search_text);
|
||||
|
||||
dlg->priv->replace_text_entry = xed_history_entry_get_entry
|
||||
(XED_HISTORY_ENTRY (dlg->priv->replace_entry));
|
||||
gtk_entry_set_activates_default (GTK_ENTRY (dlg->priv->replace_text_entry),
|
||||
TRUE);
|
||||
gtk_widget_show (dlg->priv->replace_entry);
|
||||
gtk_table_attach_defaults (GTK_TABLE (dlg->priv->table),
|
||||
dlg->priv->replace_entry,
|
||||
1, 2, 1, 2);
|
||||
|
||||
gtk_label_set_mnemonic_widget (GTK_LABEL (dlg->priv->search_label),
|
||||
dlg->priv->search_entry);
|
||||
gtk_label_set_mnemonic_widget (GTK_LABEL (dlg->priv->replace_label),
|
||||
dlg->priv->replace_entry);
|
||||
|
||||
dlg->priv->find_button = gtk_button_new_from_stock (GTK_STOCK_FIND);
|
||||
dlg->priv->replace_all_button = gtk_button_new_with_mnemonic (_("Replace _All"));
|
||||
dlg->priv->replace_button = xed_gtk_button_new_with_stock_icon (_("_Replace"),
|
||||
GTK_STOCK_FIND_AND_REPLACE);
|
||||
|
||||
gtk_dialog_add_action_widget (GTK_DIALOG (dlg),
|
||||
dlg->priv->replace_all_button,
|
||||
XED_SEARCH_DIALOG_REPLACE_ALL_RESPONSE);
|
||||
gtk_dialog_add_action_widget (GTK_DIALOG (dlg),
|
||||
dlg->priv->replace_button,
|
||||
XED_SEARCH_DIALOG_REPLACE_RESPONSE);
|
||||
gtk_dialog_add_action_widget (GTK_DIALOG (dlg),
|
||||
dlg->priv->find_button,
|
||||
XED_SEARCH_DIALOG_FIND_RESPONSE);
|
||||
g_object_set (G_OBJECT (dlg->priv->find_button),
|
||||
"can-default", TRUE,
|
||||
NULL);
|
||||
|
||||
gtk_dialog_set_default_response (GTK_DIALOG (dlg),
|
||||
XED_SEARCH_DIALOG_FIND_RESPONSE);
|
||||
|
||||
/* insensitive by default */
|
||||
gtk_dialog_set_response_sensitive (GTK_DIALOG (dlg),
|
||||
XED_SEARCH_DIALOG_FIND_RESPONSE,
|
||||
FALSE);
|
||||
gtk_dialog_set_response_sensitive (GTK_DIALOG (dlg),
|
||||
XED_SEARCH_DIALOG_REPLACE_RESPONSE,
|
||||
FALSE);
|
||||
gtk_dialog_set_response_sensitive (GTK_DIALOG (dlg),
|
||||
XED_SEARCH_DIALOG_REPLACE_ALL_RESPONSE,
|
||||
FALSE);
|
||||
|
||||
gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dlg))),
|
||||
content, FALSE, FALSE, 0);
|
||||
g_object_unref (content);
|
||||
gtk_container_set_border_width (GTK_CONTAINER (content), 5);
|
||||
|
||||
g_signal_connect (dlg->priv->search_text_entry,
|
||||
"insert_text",
|
||||
G_CALLBACK (insert_text_handler),
|
||||
NULL);
|
||||
g_signal_connect (dlg->priv->replace_text_entry,
|
||||
"insert_text",
|
||||
G_CALLBACK (insert_text_handler),
|
||||
NULL);
|
||||
g_signal_connect (dlg->priv->search_text_entry,
|
||||
"changed",
|
||||
G_CALLBACK (search_text_entry_changed),
|
||||
dlg);
|
||||
|
||||
g_signal_connect (dlg,
|
||||
"response",
|
||||
G_CALLBACK (response_handler),
|
||||
NULL);
|
||||
}
|
||||
|
||||
GtkWidget *
|
||||
xed_search_dialog_new (GtkWindow *parent,
|
||||
gboolean show_replace)
|
||||
{
|
||||
XedSearchDialog *dlg;
|
||||
|
||||
dlg = g_object_new (XED_TYPE_SEARCH_DIALOG,
|
||||
"show-replace", show_replace,
|
||||
NULL);
|
||||
|
||||
if (parent != NULL)
|
||||
{
|
||||
gtk_window_set_transient_for (GTK_WINDOW (dlg),
|
||||
parent);
|
||||
|
||||
gtk_window_set_destroy_with_parent (GTK_WINDOW (dlg),
|
||||
TRUE);
|
||||
}
|
||||
|
||||
return GTK_WIDGET (dlg);
|
||||
}
|
||||
|
||||
gboolean
|
||||
xed_search_dialog_get_show_replace (XedSearchDialog *dialog)
|
||||
{
|
||||
g_return_val_if_fail (XED_IS_SEARCH_DIALOG (dialog), FALSE);
|
||||
|
||||
return dialog->priv->show_replace;
|
||||
}
|
||||
|
||||
void
|
||||
xed_search_dialog_set_show_replace (XedSearchDialog *dialog,
|
||||
gboolean show_replace)
|
||||
{
|
||||
g_return_if_fail (XED_IS_SEARCH_DIALOG (dialog));
|
||||
|
||||
if (dialog->priv->ui_error)
|
||||
return;
|
||||
|
||||
dialog->priv->show_replace = show_replace != FALSE;
|
||||
show_replace_widgets (dialog, dialog->priv->show_replace);
|
||||
|
||||
g_object_notify (G_OBJECT (dialog), "show-replace");
|
||||
}
|
||||
|
||||
void
|
||||
xed_search_dialog_set_search_text (XedSearchDialog *dialog,
|
||||
const gchar *text)
|
||||
{
|
||||
g_return_if_fail (XED_IS_SEARCH_DIALOG (dialog));
|
||||
g_return_if_fail (text != NULL);
|
||||
|
||||
gtk_entry_set_text (GTK_ENTRY (dialog->priv->search_text_entry),
|
||||
text);
|
||||
|
||||
gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog),
|
||||
XED_SEARCH_DIALOG_FIND_RESPONSE,
|
||||
(text != '\0'));
|
||||
|
||||
gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog),
|
||||
XED_SEARCH_DIALOG_REPLACE_ALL_RESPONSE,
|
||||
(text != '\0'));
|
||||
}
|
||||
|
||||
/*
|
||||
* The text must be unescaped before searching.
|
||||
*/
|
||||
const gchar *
|
||||
xed_search_dialog_get_search_text (XedSearchDialog *dialog)
|
||||
{
|
||||
g_return_val_if_fail (XED_IS_SEARCH_DIALOG (dialog), NULL);
|
||||
|
||||
return gtk_entry_get_text (GTK_ENTRY (dialog->priv->search_text_entry));
|
||||
}
|
||||
|
||||
void
|
||||
xed_search_dialog_set_replace_text (XedSearchDialog *dialog,
|
||||
const gchar *text)
|
||||
{
|
||||
g_return_if_fail (XED_IS_SEARCH_DIALOG (dialog));
|
||||
g_return_if_fail (text != NULL);
|
||||
|
||||
gtk_entry_set_text (GTK_ENTRY (dialog->priv->replace_text_entry),
|
||||
text);
|
||||
}
|
||||
|
||||
const gchar *
|
||||
xed_search_dialog_get_replace_text (XedSearchDialog *dialog)
|
||||
{
|
||||
g_return_val_if_fail (XED_IS_SEARCH_DIALOG (dialog), NULL);
|
||||
|
||||
return gtk_entry_get_text (GTK_ENTRY (dialog->priv->replace_text_entry));
|
||||
}
|
||||
|
||||
void
|
||||
xed_search_dialog_set_match_case (XedSearchDialog *dialog,
|
||||
gboolean match_case)
|
||||
{
|
||||
g_return_if_fail (XED_IS_SEARCH_DIALOG (dialog));
|
||||
|
||||
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->priv->match_case_checkbutton),
|
||||
match_case);
|
||||
}
|
||||
|
||||
gboolean
|
||||
xed_search_dialog_get_match_case (XedSearchDialog *dialog)
|
||||
{
|
||||
g_return_val_if_fail (XED_IS_SEARCH_DIALOG (dialog), FALSE);
|
||||
|
||||
return gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->priv->match_case_checkbutton));
|
||||
}
|
||||
|
||||
void
|
||||
xed_search_dialog_set_entire_word (XedSearchDialog *dialog,
|
||||
gboolean entire_word)
|
||||
{
|
||||
g_return_if_fail (XED_IS_SEARCH_DIALOG (dialog));
|
||||
|
||||
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->priv->entire_word_checkbutton),
|
||||
entire_word);
|
||||
}
|
||||
|
||||
gboolean
|
||||
xed_search_dialog_get_entire_word (XedSearchDialog *dialog)
|
||||
{
|
||||
g_return_val_if_fail (XED_IS_SEARCH_DIALOG (dialog), FALSE);
|
||||
|
||||
return gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->priv->entire_word_checkbutton));
|
||||
}
|
||||
|
||||
void
|
||||
xed_search_dialog_set_backwards (XedSearchDialog *dialog,
|
||||
gboolean backwards)
|
||||
{
|
||||
g_return_if_fail (XED_IS_SEARCH_DIALOG (dialog));
|
||||
|
||||
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->priv->backwards_checkbutton),
|
||||
backwards);
|
||||
}
|
||||
|
||||
gboolean
|
||||
xed_search_dialog_get_backwards (XedSearchDialog *dialog)
|
||||
{
|
||||
g_return_val_if_fail (XED_IS_SEARCH_DIALOG (dialog), FALSE);
|
||||
|
||||
return gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->priv->backwards_checkbutton));
|
||||
}
|
||||
|
||||
void
|
||||
xed_search_dialog_set_wrap_around (XedSearchDialog *dialog,
|
||||
gboolean wrap_around)
|
||||
{
|
||||
g_return_if_fail (XED_IS_SEARCH_DIALOG (dialog));
|
||||
|
||||
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->priv->wrap_around_checkbutton),
|
||||
wrap_around);
|
||||
}
|
||||
|
||||
gboolean
|
||||
xed_search_dialog_get_wrap_around (XedSearchDialog *dialog)
|
||||
{
|
||||
g_return_val_if_fail (XED_IS_SEARCH_DIALOG (dialog), FALSE);
|
||||
|
||||
return gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->priv->wrap_around_checkbutton));
|
||||
}
|
||||
|
||||
void
|
||||
xed_search_dialog_set_parse_escapes (XedSearchDialog *dialog,
|
||||
gboolean parse_escapes)
|
||||
{
|
||||
g_return_if_fail (XED_IS_SEARCH_DIALOG (dialog));
|
||||
|
||||
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->priv->parse_escapes_checkbutton),
|
||||
parse_escapes);
|
||||
}
|
||||
|
||||
gboolean
|
||||
xed_search_dialog_get_parse_escapes (XedSearchDialog *dialog)
|
||||
{
|
||||
g_return_val_if_fail (XED_IS_SEARCH_DIALOG (dialog), FALSE);
|
||||
|
||||
return gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->priv->parse_escapes_checkbutton));
|
||||
}
|
|
@ -1,133 +0,0 @@
|
|||
/*
|
||||
* xed-search-dialog.h
|
||||
* This file is part of xed
|
||||
*
|
||||
* Copyright (C) 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 of the License, 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., 51 Franklin St, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Modified by the xed Team, 2005. See the AUTHORS file for a
|
||||
* list of people on the xed Team.
|
||||
* See the ChangeLog files for a list of changes.
|
||||
*
|
||||
* $Id$
|
||||
*/
|
||||
|
||||
#ifndef __XED_SEARCH_DIALOG_H__
|
||||
#define __XED_SEARCH_DIALOG_H__
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
/*
|
||||
* Type checking and casting macros
|
||||
*/
|
||||
#define XED_TYPE_SEARCH_DIALOG (xed_search_dialog_get_type())
|
||||
#define XED_SEARCH_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), XED_TYPE_SEARCH_DIALOG, XedSearchDialog))
|
||||
#define XED_SEARCH_DIALOG_CONST(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), XED_TYPE_SEARCH_DIALOG, XedSearchDialog const))
|
||||
#define XED_SEARCH_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), XED_TYPE_SEARCH_DIALOG, XedSearchDialogClass))
|
||||
#define XED_IS_SEARCH_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), XED_TYPE_SEARCH_DIALOG))
|
||||
#define XED_IS_SEARCH_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), XED_TYPE_SEARCH_DIALOG))
|
||||
#define XED_SEARCH_DIALOG_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), XED_TYPE_SEARCH_DIALOG, XedSearchDialogClass))
|
||||
|
||||
/* Private structure type */
|
||||
typedef struct _XedSearchDialogPrivate XedSearchDialogPrivate;
|
||||
|
||||
/*
|
||||
* Main object structure
|
||||
*/
|
||||
typedef struct _XedSearchDialog XedSearchDialog;
|
||||
|
||||
struct _XedSearchDialog
|
||||
{
|
||||
GtkDialog dialog;
|
||||
|
||||
/*< private > */
|
||||
XedSearchDialogPrivate *priv;
|
||||
};
|
||||
|
||||
/*
|
||||
* Class definition
|
||||
*/
|
||||
typedef struct _XedSearchDialogClass XedSearchDialogClass;
|
||||
|
||||
struct _XedSearchDialogClass
|
||||
{
|
||||
GtkDialogClass parent_class;
|
||||
|
||||
/* Key bindings */
|
||||
gboolean (* show_replace) (XedSearchDialog *dlg);
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
XED_SEARCH_DIALOG_FIND_RESPONSE = 100,
|
||||
XED_SEARCH_DIALOG_REPLACE_RESPONSE,
|
||||
XED_SEARCH_DIALOG_REPLACE_ALL_RESPONSE
|
||||
};
|
||||
|
||||
/*
|
||||
* Public methods
|
||||
*/
|
||||
GType xed_search_dialog_get_type (void) G_GNUC_CONST;
|
||||
|
||||
GtkWidget *xed_search_dialog_new (GtkWindow *parent,
|
||||
gboolean show_replace);
|
||||
|
||||
void xed_search_dialog_present_with_time (XedSearchDialog *dialog,
|
||||
guint32 timestamp);
|
||||
|
||||
gboolean xed_search_dialog_get_show_replace (XedSearchDialog *dialog);
|
||||
|
||||
void xed_search_dialog_set_show_replace (XedSearchDialog *dialog,
|
||||
gboolean show_replace);
|
||||
|
||||
|
||||
void xed_search_dialog_set_search_text (XedSearchDialog *dialog,
|
||||
const gchar *text);
|
||||
const gchar *xed_search_dialog_get_search_text (XedSearchDialog *dialog);
|
||||
|
||||
void xed_search_dialog_set_replace_text (XedSearchDialog *dialog,
|
||||
const gchar *text);
|
||||
const gchar *xed_search_dialog_get_replace_text (XedSearchDialog *dialog);
|
||||
|
||||
void xed_search_dialog_set_match_case (XedSearchDialog *dialog,
|
||||
gboolean match_case);
|
||||
gboolean xed_search_dialog_get_match_case (XedSearchDialog *dialog);
|
||||
|
||||
void xed_search_dialog_set_entire_word (XedSearchDialog *dialog,
|
||||
gboolean entire_word);
|
||||
gboolean xed_search_dialog_get_entire_word (XedSearchDialog *dialog);
|
||||
|
||||
void xed_search_dialog_set_backwards (XedSearchDialog *dialog,
|
||||
gboolean backwards);
|
||||
gboolean xed_search_dialog_get_backwards (XedSearchDialog *dialog);
|
||||
|
||||
void xed_search_dialog_set_wrap_around (XedSearchDialog *dialog,
|
||||
gboolean wrap_around);
|
||||
gboolean xed_search_dialog_get_wrap_around (XedSearchDialog *dialog);
|
||||
|
||||
|
||||
void xed_search_dialog_set_parse_escapes (XedSearchDialog *dialog,
|
||||
gboolean parse_escapes);
|
||||
gboolean xed_search_dialog_get_parse_escapes (XedSearchDialog *dialog);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __XED_SEARCH_DIALOG_H__ */
|
|
@ -1,272 +0,0 @@
|
|||
<?xml version="1.0"?>
|
||||
<!--*- mode: xml -*-->
|
||||
<interface>
|
||||
<object class="GtkDialog" id="dialog">
|
||||
<property name="title" translatable="yes">Replace</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">False</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>
|
||||
<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_DEFAULT_STYLE</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="replace_all_button">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_default">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="label" translatable="yes">Replace All</property>
|
||||
<property name="use_underline">True</property>
|
||||
<property name="relief">GTK_RELIEF_NORMAL</property>
|
||||
<property name="focus_on_click">True</property>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkButton" id="replace_button">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_default">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="label" translatable="yes">Replace</property>
|
||||
<property name="use_underline">True</property>
|
||||
<property name="relief">GTK_RELIEF_NORMAL</property>
|
||||
<property name="focus_on_click">True</property>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkButton" id="find_next_button">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_default">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="label">gtk-find</property>
|
||||
<property name="use_stock">True</property>
|
||||
<property name="relief">GTK_RELIEF_NORMAL</property>
|
||||
<property name="focus_on_click">True</property>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="padding">0</property>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">False</property>
|
||||
<property name="pack_type">GTK_PACK_END</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkVBox" id="search_dialog_content">
|
||||
<property name="border_width">5</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="homogeneous">False</property>
|
||||
<property name="spacing">18</property>
|
||||
<child>
|
||||
<object class="GtkTable" id="table">
|
||||
<property name="visible">True</property>
|
||||
<property name="n_rows">2</property>
|
||||
<property name="n_columns">2</property>
|
||||
<property name="homogeneous">False</property>
|
||||
<property name="row_spacing">12</property>
|
||||
<property name="column_spacing">12</property>
|
||||
<child>
|
||||
<object class="GtkLabel" id="search_label">
|
||||
<property name="visible">True</property>
|
||||
<property name="label" translatable="yes">_Search for: </property>
|
||||
<property name="use_underline">True</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">0</property>
|
||||
<property name="bottom_attach">1</property>
|
||||
<property name="x_options">fill</property>
|
||||
<property name="y_options"/>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel" id="replace_with_label">
|
||||
<property name="visible">True</property>
|
||||
<property name="label" translatable="yes">Replace _with: </property>
|
||||
<property name="use_underline">True</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>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="padding">0</property>
|
||||
<property name="expand">True</property>
|
||||
<property name="fill">True</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkVBox" id="vbox3">
|
||||
<property name="visible">True</property>
|
||||
<property name="homogeneous">False</property>
|
||||
<property name="spacing">12</property>
|
||||
<child>
|
||||
<object class="GtkCheckButton" id="match_case_checkbutton">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="label" translatable="yes">_Match case</property>
|
||||
<property name="use_underline">True</property>
|
||||
<property name="relief">GTK_RELIEF_NORMAL</property>
|
||||
<property name="focus_on_click">True</property>
|
||||
<property name="active">False</property>
|
||||
<property name="inconsistent">False</property>
|
||||
<property name="draw_indicator">True</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="padding">0</property>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">False</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkCheckButton" id="entire_word_checkbutton">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="label" translatable="yes">Match _entire word only</property>
|
||||
<property name="use_underline">True</property>
|
||||
<property name="relief">GTK_RELIEF_NORMAL</property>
|
||||
<property name="focus_on_click">True</property>
|
||||
<property name="active">False</property>
|
||||
<property name="inconsistent">False</property>
|
||||
<property name="draw_indicator">True</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="padding">0</property>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">False</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkCheckButton" id="search_backwards_checkbutton">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="label" translatable="yes">Search _backwards</property>
|
||||
<property name="use_underline">True</property>
|
||||
<property name="relief">GTK_RELIEF_NORMAL</property>
|
||||
<property name="focus_on_click">True</property>
|
||||
<property name="active">False</property>
|
||||
<property name="inconsistent">False</property>
|
||||
<property name="draw_indicator">True</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="padding">0</property>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">False</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkCheckButton" id="wrap_around_checkbutton">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="label" translatable="yes">_Wrap around</property>
|
||||
<property name="use_underline">True</property>
|
||||
<property name="relief">GTK_RELIEF_NORMAL</property>
|
||||
<property name="focus_on_click">True</property>
|
||||
<property name="active">True</property>
|
||||
<property name="inconsistent">False</property>
|
||||
<property name="draw_indicator">True</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="padding">0</property>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">False</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkCheckButton" id="parse_escapes_checkbutton">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="label" translatable="yes">_Parse escape sequences (e.g. \n)</property>
|
||||
<property name="use_underline">True</property>
|
||||
<property name="relief">GTK_RELIEF_NORMAL</property>
|
||||
<property name="focus_on_click">True</property>
|
||||
<property name="active">True</property>
|
||||
<property name="inconsistent">False</property>
|
||||
<property name="draw_indicator">True</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>
|
||||
</child>
|
||||
<action-widgets>
|
||||
<action-widget response="0">close_button</action-widget>
|
||||
<action-widget response="0">replace_all_button</action-widget>
|
||||
<action-widget response="0">replace_button</action-widget>
|
||||
<action-widget response="0">find_next_button</action-widget>
|
||||
</action-widgets>
|
||||
</object>
|
||||
</interface>
|
|
@ -1,35 +1,3 @@
|
|||
/*
|
||||
* xed-search-commands.c
|
||||
* This file is part of xed
|
||||
*
|
||||
* Copyright (C) 1998, 1999 Alex Roberts, Evan Lawrence
|
||||
* Copyright (C) 2000, 2001 Chema Celorio, Paolo Maggi
|
||||
* Copyright (C) 2002-2006 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 of the License, 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., 51 Franklin St, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Modified by the xed Team, 1998-2006. See the AUTHORS file for a
|
||||
* list of people on the xed Team.
|
||||
* See the ChangeLog files for a list of changes.
|
||||
*
|
||||
* $Id$
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
@ -41,750 +9,63 @@
|
|||
|
||||
#include "xed-commands.h"
|
||||
#include "xed-debug.h"
|
||||
#include "xed-statusbar.h"
|
||||
#include "xed-window.h"
|
||||
#include "xed-window-private.h"
|
||||
#include "xed-utils.h"
|
||||
#include "dialogs/xed-search-dialog.h"
|
||||
#include "xed-searchbar.h"
|
||||
|
||||
#define XED_SEARCH_DIALOG_KEY "xed-search-dialog-key"
|
||||
#define XED_LAST_SEARCH_DATA_KEY "xed-last-search-data-key"
|
||||
|
||||
typedef struct _LastSearchData LastSearchData;
|
||||
struct _LastSearchData
|
||||
void
|
||||
_xed_cmd_search_find (GtkAction *action, XedWindow *window)
|
||||
{
|
||||
gint x;
|
||||
gint y;
|
||||
};
|
||||
|
||||
static void
|
||||
last_search_data_free (LastSearchData *data)
|
||||
{
|
||||
g_slice_free (LastSearchData, data);
|
||||
}
|
||||
|
||||
static void
|
||||
last_search_data_restore_position (XedSearchDialog *dlg)
|
||||
{
|
||||
LastSearchData *data;
|
||||
|
||||
data = g_object_get_data (G_OBJECT (dlg), XED_LAST_SEARCH_DATA_KEY);
|
||||
|
||||
if (data != NULL)
|
||||
{
|
||||
gtk_window_move (GTK_WINDOW (dlg),
|
||||
data->x,
|
||||
data->y);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
last_search_data_store_position (XedSearchDialog *dlg)
|
||||
{
|
||||
LastSearchData *data;
|
||||
|
||||
data = g_object_get_data (G_OBJECT (dlg), XED_LAST_SEARCH_DATA_KEY);
|
||||
|
||||
if (data == NULL)
|
||||
{
|
||||
data = g_slice_new (LastSearchData);
|
||||
|
||||
g_object_set_data_full (G_OBJECT (dlg),
|
||||
XED_LAST_SEARCH_DATA_KEY,
|
||||
data,
|
||||
(GDestroyNotify) last_search_data_free);
|
||||
}
|
||||
|
||||
gtk_window_get_position (GTK_WINDOW (dlg),
|
||||
&data->x,
|
||||
&data->y);
|
||||
}
|
||||
|
||||
/* Use occurrences only for Replace All */
|
||||
static void
|
||||
text_found (XedWindow *window,
|
||||
gint occurrences)
|
||||
{
|
||||
if (occurrences > 1)
|
||||
{
|
||||
xed_statusbar_flash_message (XED_STATUSBAR (window->priv->statusbar),
|
||||
window->priv->generic_message_cid,
|
||||
ngettext("Found and replaced %d occurrence",
|
||||
"Found and replaced %d occurrences",
|
||||
occurrences),
|
||||
occurrences);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (occurrences == 1)
|
||||
xed_statusbar_flash_message (XED_STATUSBAR (window->priv->statusbar),
|
||||
window->priv->generic_message_cid,
|
||||
_("Found and replaced one occurrence"));
|
||||
else
|
||||
xed_statusbar_flash_message (XED_STATUSBAR (window->priv->statusbar),
|
||||
window->priv->generic_message_cid,
|
||||
" ");
|
||||
}
|
||||
}
|
||||
|
||||
#define MAX_MSG_LENGTH 40
|
||||
static void
|
||||
text_not_found (XedWindow *window,
|
||||
const gchar *text)
|
||||
{
|
||||
gchar *searched;
|
||||
|
||||
searched = xed_utils_str_end_truncate (text, MAX_MSG_LENGTH);
|
||||
|
||||
xed_statusbar_flash_message (XED_STATUSBAR (window->priv->statusbar),
|
||||
window->priv->generic_message_cid,
|
||||
/* Translators: %s is replaced by the text
|
||||
entered by the user in the search box */
|
||||
_("\"%s\" not found"), searched);
|
||||
g_free (searched);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
run_search (XedView *view,
|
||||
gboolean wrap_around,
|
||||
gboolean search_backwards)
|
||||
{
|
||||
XedDocument *doc;
|
||||
GtkTextIter start_iter;
|
||||
GtkTextIter match_start;
|
||||
GtkTextIter match_end;
|
||||
gboolean found = FALSE;
|
||||
|
||||
doc = XED_DOCUMENT (gtk_text_view_get_buffer (GTK_TEXT_VIEW (view)));
|
||||
|
||||
if (!search_backwards)
|
||||
{
|
||||
gtk_text_buffer_get_selection_bounds (GTK_TEXT_BUFFER (doc),
|
||||
NULL,
|
||||
&start_iter);
|
||||
|
||||
found = xed_document_search_forward (doc,
|
||||
&start_iter,
|
||||
NULL,
|
||||
&match_start,
|
||||
&match_end);
|
||||
}
|
||||
else
|
||||
{
|
||||
gtk_text_buffer_get_selection_bounds (GTK_TEXT_BUFFER (doc),
|
||||
&start_iter,
|
||||
NULL);
|
||||
|
||||
found = xed_document_search_backward (doc,
|
||||
NULL,
|
||||
&start_iter,
|
||||
&match_start,
|
||||
&match_end);
|
||||
}
|
||||
|
||||
if (!found && wrap_around)
|
||||
{
|
||||
if (!search_backwards)
|
||||
found = xed_document_search_forward (doc,
|
||||
NULL,
|
||||
NULL, /* FIXME: set the end_inter */
|
||||
&match_start,
|
||||
&match_end);
|
||||
else
|
||||
found = xed_document_search_backward (doc,
|
||||
NULL, /* FIXME: set the start_inter */
|
||||
NULL,
|
||||
&match_start,
|
||||
&match_end);
|
||||
}
|
||||
|
||||
if (found)
|
||||
{
|
||||
gtk_text_buffer_place_cursor (GTK_TEXT_BUFFER (doc),
|
||||
&match_start);
|
||||
|
||||
gtk_text_buffer_move_mark_by_name (GTK_TEXT_BUFFER (doc),
|
||||
"selection_bound",
|
||||
&match_end);
|
||||
|
||||
xed_view_scroll_to_cursor (view);
|
||||
}
|
||||
else
|
||||
{
|
||||
gtk_text_buffer_place_cursor (GTK_TEXT_BUFFER (doc),
|
||||
&start_iter);
|
||||
}
|
||||
|
||||
return found;
|
||||
}
|
||||
|
||||
static void
|
||||
do_find (XedSearchDialog *dialog,
|
||||
XedWindow *window)
|
||||
{
|
||||
XedView *active_view;
|
||||
XedDocument *doc;
|
||||
gchar *search_text;
|
||||
const gchar *entry_text;
|
||||
gboolean match_case;
|
||||
gboolean entire_word;
|
||||
gboolean wrap_around;
|
||||
gboolean search_backwards;
|
||||
gboolean parse_escapes;
|
||||
guint flags = 0;
|
||||
guint old_flags = 0;
|
||||
gboolean found;
|
||||
|
||||
/* TODO: make the dialog insensitive when all the tabs are closed
|
||||
* and assert here that the view is not NULL */
|
||||
active_view = xed_window_get_active_view (window);
|
||||
if (active_view == NULL)
|
||||
return;
|
||||
|
||||
doc = XED_DOCUMENT (gtk_text_view_get_buffer (GTK_TEXT_VIEW (active_view)));
|
||||
|
||||
match_case = xed_search_dialog_get_match_case (dialog);
|
||||
entire_word = xed_search_dialog_get_entire_word (dialog);
|
||||
search_backwards = xed_search_dialog_get_backwards (dialog);
|
||||
wrap_around = xed_search_dialog_get_wrap_around (dialog);
|
||||
parse_escapes = xed_search_dialog_get_parse_escapes (dialog);
|
||||
|
||||
if (!parse_escapes) {
|
||||
entry_text = xed_utils_escape_search_text (xed_search_dialog_get_search_text (dialog));
|
||||
} else {
|
||||
entry_text = xed_search_dialog_get_search_text (dialog);
|
||||
}
|
||||
|
||||
XED_SEARCH_SET_CASE_SENSITIVE (flags, match_case);
|
||||
XED_SEARCH_SET_ENTIRE_WORD (flags, entire_word);
|
||||
|
||||
search_text = xed_document_get_search_text (doc, &old_flags);
|
||||
|
||||
if ((search_text == NULL) ||
|
||||
(strcmp (search_text, entry_text) != 0) ||
|
||||
(flags != old_flags))
|
||||
{
|
||||
xed_document_set_search_text (doc, entry_text, flags);
|
||||
}
|
||||
|
||||
g_free (search_text);
|
||||
|
||||
found = run_search (active_view,
|
||||
wrap_around,
|
||||
search_backwards);
|
||||
|
||||
if (found)
|
||||
text_found (window, 0);
|
||||
else {
|
||||
if (!parse_escapes) {
|
||||
text_not_found (window, xed_utils_unescape_search_text (entry_text));
|
||||
} else {
|
||||
text_not_found (window, entry_text);
|
||||
}
|
||||
}
|
||||
|
||||
gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog),
|
||||
XED_SEARCH_DIALOG_REPLACE_RESPONSE,
|
||||
found);
|
||||
}
|
||||
|
||||
/* FIXME: move in xed-document.c and share it with xed-view */
|
||||
static gboolean
|
||||
get_selected_text (GtkTextBuffer *doc,
|
||||
gchar **selected_text,
|
||||
gint *len)
|
||||
{
|
||||
GtkTextIter start, end;
|
||||
|
||||
g_return_val_if_fail (selected_text != NULL, FALSE);
|
||||
g_return_val_if_fail (*selected_text == NULL, FALSE);
|
||||
|
||||
if (!gtk_text_buffer_get_selection_bounds (doc, &start, &end))
|
||||
{
|
||||
if (len != NULL)
|
||||
len = 0;
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
*selected_text = gtk_text_buffer_get_slice (doc, &start, &end, TRUE);
|
||||
|
||||
if (len != NULL)
|
||||
*len = g_utf8_strlen (*selected_text, -1);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
replace_selected_text (GtkTextBuffer *buffer,
|
||||
const gchar *replace)
|
||||
{
|
||||
g_return_if_fail (gtk_text_buffer_get_selection_bounds (buffer, NULL, NULL));
|
||||
g_return_if_fail (replace != NULL);
|
||||
|
||||
gtk_text_buffer_begin_user_action (buffer);
|
||||
|
||||
gtk_text_buffer_delete_selection (buffer, FALSE, TRUE);
|
||||
|
||||
gtk_text_buffer_insert_at_cursor (buffer, replace, strlen (replace));
|
||||
|
||||
gtk_text_buffer_end_user_action (buffer);
|
||||
}
|
||||
|
||||
static void
|
||||
do_replace (XedSearchDialog *dialog,
|
||||
XedWindow *window)
|
||||
{
|
||||
XedDocument *doc;
|
||||
const gchar *search_entry_text;
|
||||
const gchar *replace_entry_text;
|
||||
gchar *unescaped_search_text;
|
||||
gchar *unescaped_replace_text;
|
||||
gchar *selected_text = NULL;
|
||||
gboolean match_case;
|
||||
gboolean parse_escapes;
|
||||
|
||||
doc = xed_window_get_active_document (window);
|
||||
if (doc == NULL)
|
||||
return;
|
||||
|
||||
parse_escapes = xed_search_dialog_get_parse_escapes (dialog);
|
||||
if (!parse_escapes) {
|
||||
search_entry_text = xed_utils_escape_search_text (xed_search_dialog_get_search_text (dialog));
|
||||
} else {
|
||||
search_entry_text = xed_search_dialog_get_search_text (dialog);
|
||||
}
|
||||
g_return_if_fail ((search_entry_text) != NULL);
|
||||
g_return_if_fail ((*search_entry_text) != '\0');
|
||||
|
||||
/* replace text may be "", we just delete */
|
||||
if (!parse_escapes) {
|
||||
replace_entry_text = xed_utils_escape_search_text (xed_search_dialog_get_replace_text (dialog));
|
||||
} else {
|
||||
replace_entry_text = xed_search_dialog_get_replace_text (dialog);
|
||||
}
|
||||
g_return_if_fail ((replace_entry_text) != NULL);
|
||||
|
||||
unescaped_search_text = xed_utils_unescape_search_text (search_entry_text);
|
||||
|
||||
get_selected_text (GTK_TEXT_BUFFER (doc),
|
||||
&selected_text,
|
||||
NULL);
|
||||
|
||||
match_case = xed_search_dialog_get_match_case (dialog);
|
||||
|
||||
if ((selected_text == NULL) ||
|
||||
(match_case && (strcmp (selected_text, unescaped_search_text) != 0)) ||
|
||||
(!match_case && !g_utf8_caselessnmatch (selected_text,
|
||||
unescaped_search_text,
|
||||
strlen (selected_text),
|
||||
strlen (unescaped_search_text)) != 0))
|
||||
{
|
||||
do_find (dialog, window);
|
||||
g_free (unescaped_search_text);
|
||||
g_free (selected_text);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
unescaped_replace_text = xed_utils_unescape_search_text (replace_entry_text);
|
||||
replace_selected_text (GTK_TEXT_BUFFER (doc), unescaped_replace_text);
|
||||
|
||||
g_free (unescaped_search_text);
|
||||
g_free (selected_text);
|
||||
g_free (unescaped_replace_text);
|
||||
|
||||
do_find (dialog, window);
|
||||
}
|
||||
|
||||
static void
|
||||
do_replace_all (XedSearchDialog *dialog,
|
||||
XedWindow *window)
|
||||
{
|
||||
XedView *active_view;
|
||||
XedDocument *doc;
|
||||
const gchar *search_entry_text;
|
||||
const gchar *replace_entry_text;
|
||||
gboolean match_case;
|
||||
gboolean entire_word;
|
||||
gboolean parse_escapes;
|
||||
guint flags = 0;
|
||||
gint count;
|
||||
|
||||
active_view = xed_window_get_active_view (window);
|
||||
if (active_view == NULL)
|
||||
return;
|
||||
|
||||
doc = XED_DOCUMENT (gtk_text_view_get_buffer (GTK_TEXT_VIEW (active_view)));
|
||||
|
||||
parse_escapes = xed_search_dialog_get_parse_escapes (dialog);
|
||||
if (!parse_escapes) {
|
||||
search_entry_text = xed_utils_escape_search_text(xed_search_dialog_get_search_text (dialog));
|
||||
} else {
|
||||
search_entry_text = xed_search_dialog_get_search_text (dialog);
|
||||
}
|
||||
g_return_if_fail ((search_entry_text) != NULL);
|
||||
g_return_if_fail ((*search_entry_text) != '\0');
|
||||
|
||||
/* replace text may be "", we just delete all occurrencies */
|
||||
if (!parse_escapes) {
|
||||
replace_entry_text = xed_utils_escape_search_text (xed_search_dialog_get_replace_text (dialog));
|
||||
} else {
|
||||
replace_entry_text = xed_search_dialog_get_replace_text (dialog);
|
||||
}
|
||||
g_return_if_fail ((replace_entry_text) != NULL);
|
||||
|
||||
match_case = xed_search_dialog_get_match_case (dialog);
|
||||
entire_word = xed_search_dialog_get_entire_word (dialog);
|
||||
|
||||
XED_SEARCH_SET_CASE_SENSITIVE (flags, match_case);
|
||||
XED_SEARCH_SET_ENTIRE_WORD (flags, entire_word);
|
||||
|
||||
count = xed_document_replace_all (doc,
|
||||
search_entry_text,
|
||||
replace_entry_text,
|
||||
flags);
|
||||
|
||||
if (count > 0)
|
||||
{
|
||||
text_found (window, count);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!parse_escapes) {
|
||||
text_not_found (window, xed_utils_unescape_search_text (search_entry_text));
|
||||
} else {
|
||||
text_not_found (window, search_entry_text);
|
||||
}
|
||||
}
|
||||
|
||||
gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog),
|
||||
XED_SEARCH_DIALOG_REPLACE_RESPONSE,
|
||||
FALSE);
|
||||
}
|
||||
|
||||
static void
|
||||
search_dialog_response_cb (XedSearchDialog *dialog,
|
||||
gint response_id,
|
||||
XedWindow *window)
|
||||
{
|
||||
xed_debug (DEBUG_COMMANDS);
|
||||
|
||||
switch (response_id)
|
||||
{
|
||||
case XED_SEARCH_DIALOG_FIND_RESPONSE:
|
||||
do_find (dialog, window);
|
||||
break;
|
||||
case XED_SEARCH_DIALOG_REPLACE_RESPONSE:
|
||||
do_replace (dialog, window);
|
||||
break;
|
||||
case XED_SEARCH_DIALOG_REPLACE_ALL_RESPONSE:
|
||||
do_replace_all (dialog, window);
|
||||
break;
|
||||
default:
|
||||
last_search_data_store_position (dialog);
|
||||
gtk_widget_hide (GTK_WIDGET (dialog));
|
||||
}
|
||||
}
|
||||
|
||||
static gboolean
|
||||
search_dialog_delete_event_cb (GtkWidget *widget,
|
||||
GdkEventAny *event,
|
||||
gpointer user_data)
|
||||
{
|
||||
xed_debug (DEBUG_COMMANDS);
|
||||
|
||||
/* prevent destruction */
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
search_dialog_destroyed (XedWindow *window,
|
||||
XedSearchDialog *dialog)
|
||||
{
|
||||
xed_debug (DEBUG_COMMANDS);
|
||||
|
||||
g_object_set_data (G_OBJECT (window),
|
||||
XED_SEARCH_DIALOG_KEY,
|
||||
NULL);
|
||||
g_object_set_data (G_OBJECT (dialog),
|
||||
XED_LAST_SEARCH_DATA_KEY,
|
||||
NULL);
|
||||
}
|
||||
|
||||
static GtkWidget *
|
||||
create_dialog (XedWindow *window, gboolean show_replace)
|
||||
{
|
||||
GtkWidget *dialog;
|
||||
|
||||
dialog = xed_search_dialog_new (GTK_WINDOW (window), show_replace);
|
||||
|
||||
g_signal_connect (dialog,
|
||||
"response",
|
||||
G_CALLBACK (search_dialog_response_cb),
|
||||
window);
|
||||
g_signal_connect (dialog,
|
||||
"delete-event",
|
||||
G_CALLBACK (search_dialog_delete_event_cb),
|
||||
NULL);
|
||||
|
||||
g_object_set_data (G_OBJECT (window),
|
||||
XED_SEARCH_DIALOG_KEY,
|
||||
dialog);
|
||||
|
||||
g_object_weak_ref (G_OBJECT (dialog),
|
||||
(GWeakNotify) search_dialog_destroyed,
|
||||
window);
|
||||
|
||||
return dialog;
|
||||
xed_searchbar_show (xed_window_get_searchbar (window), FALSE);
|
||||
}
|
||||
|
||||
void
|
||||
_xed_cmd_search_find (GtkAction *action,
|
||||
XedWindow *window)
|
||||
_xed_cmd_search_replace (GtkAction *action, XedWindow *window)
|
||||
{
|
||||
gpointer data;
|
||||
GtkWidget *search_dialog;
|
||||
XedDocument *doc;
|
||||
gboolean selection_exists;
|
||||
gboolean parse_escapes;
|
||||
gchar *find_text = NULL;
|
||||
const gchar *search_text = NULL;
|
||||
gint sel_len;
|
||||
|
||||
xed_debug (DEBUG_COMMANDS);
|
||||
|
||||
data = g_object_get_data (G_OBJECT (window), XED_SEARCH_DIALOG_KEY);
|
||||
|
||||
if (data == NULL)
|
||||
{
|
||||
search_dialog = create_dialog (window, FALSE);
|
||||
}
|
||||
else
|
||||
{
|
||||
g_return_if_fail (XED_IS_SEARCH_DIALOG (data));
|
||||
|
||||
search_dialog = GTK_WIDGET (data);
|
||||
|
||||
/* turn the dialog into a find dialog if needed */
|
||||
if (xed_search_dialog_get_show_replace (XED_SEARCH_DIALOG (search_dialog)))
|
||||
xed_search_dialog_set_show_replace (XED_SEARCH_DIALOG (search_dialog),
|
||||
FALSE);
|
||||
}
|
||||
|
||||
doc = xed_window_get_active_document (window);
|
||||
g_return_if_fail (doc != NULL);
|
||||
|
||||
selection_exists = get_selected_text (GTK_TEXT_BUFFER (doc),
|
||||
&find_text,
|
||||
&sel_len);
|
||||
|
||||
if (selection_exists && find_text != NULL && sel_len < 80)
|
||||
{
|
||||
/*
|
||||
* Special case: if the currently selected text
|
||||
* is the same as the unescaped search text and
|
||||
* escape sequence parsing is activated, use the
|
||||
* same old search text. (Without this, if you e.g.
|
||||
* search for '\n' in escaped mode and then open
|
||||
* the search dialog again, you'll get an unprintable
|
||||
* single-character literal '\n' in the "search for"
|
||||
* box).
|
||||
*/
|
||||
parse_escapes = xed_search_dialog_get_parse_escapes (XED_SEARCH_DIALOG (search_dialog));
|
||||
search_text = xed_search_dialog_get_search_text (XED_SEARCH_DIALOG (search_dialog));
|
||||
if (!(search_text != NULL
|
||||
&& !strcmp(xed_utils_unescape_search_text(search_text), find_text)
|
||||
&& parse_escapes)) {
|
||||
/* General case */
|
||||
xed_search_dialog_set_search_text (XED_SEARCH_DIALOG (search_dialog),
|
||||
find_text);
|
||||
}
|
||||
g_free (find_text);
|
||||
}
|
||||
else
|
||||
{
|
||||
g_free (find_text);
|
||||
}
|
||||
|
||||
gtk_widget_show (search_dialog);
|
||||
last_search_data_restore_position (XED_SEARCH_DIALOG (search_dialog));
|
||||
xed_search_dialog_present_with_time (XED_SEARCH_DIALOG (search_dialog),
|
||||
GDK_CURRENT_TIME);
|
||||
xed_searchbar_show (xed_window_get_searchbar (window), TRUE);
|
||||
}
|
||||
|
||||
void
|
||||
_xed_cmd_search_replace (GtkAction *action,
|
||||
XedWindow *window)
|
||||
_xed_cmd_search_find_next (GtkAction *action, XedWindow *window)
|
||||
{
|
||||
gpointer data;
|
||||
GtkWidget *replace_dialog;
|
||||
XedDocument *doc;
|
||||
gboolean selection_exists;
|
||||
gboolean parse_escapes;
|
||||
gchar *find_text = NULL;
|
||||
const gchar *search_text = NULL;
|
||||
gint sel_len;
|
||||
|
||||
xed_debug (DEBUG_COMMANDS);
|
||||
|
||||
data = g_object_get_data (G_OBJECT (window), XED_SEARCH_DIALOG_KEY);
|
||||
|
||||
if (data == NULL)
|
||||
{
|
||||
replace_dialog = create_dialog (window, TRUE);
|
||||
}
|
||||
else
|
||||
{
|
||||
g_return_if_fail (XED_IS_SEARCH_DIALOG (data));
|
||||
|
||||
replace_dialog = GTK_WIDGET (data);
|
||||
|
||||
/* turn the dialog into a find dialog if needed */
|
||||
if (!xed_search_dialog_get_show_replace (XED_SEARCH_DIALOG (replace_dialog)))
|
||||
xed_search_dialog_set_show_replace (XED_SEARCH_DIALOG (replace_dialog),
|
||||
TRUE);
|
||||
}
|
||||
|
||||
doc = xed_window_get_active_document (window);
|
||||
g_return_if_fail (doc != NULL);
|
||||
|
||||
selection_exists = get_selected_text (GTK_TEXT_BUFFER (doc),
|
||||
&find_text,
|
||||
&sel_len);
|
||||
|
||||
if (selection_exists && find_text != NULL && sel_len < 80)
|
||||
{
|
||||
/*
|
||||
* Special case: if the currently selected text
|
||||
* is the same as the unescaped search text and
|
||||
* escape sequence parsing is activated, use the
|
||||
* same old search text. (Without this, if you e.g.
|
||||
* search for '\n' in escaped mode and then open
|
||||
* the search dialog again, you'll get an unprintable
|
||||
* single-character literal '\n' in the "search for"
|
||||
* box).
|
||||
*/
|
||||
parse_escapes = xed_search_dialog_get_parse_escapes (XED_SEARCH_DIALOG (replace_dialog));
|
||||
search_text = xed_search_dialog_get_search_text (XED_SEARCH_DIALOG (replace_dialog));
|
||||
if (!(search_text != NULL
|
||||
&& !strcmp(xed_utils_unescape_search_text(search_text), find_text)
|
||||
&& parse_escapes)) {
|
||||
/* General case */
|
||||
xed_search_dialog_set_search_text (XED_SEARCH_DIALOG (replace_dialog),
|
||||
find_text);
|
||||
}
|
||||
g_free (find_text);
|
||||
}
|
||||
else
|
||||
{
|
||||
g_free (find_text);
|
||||
}
|
||||
|
||||
gtk_widget_show (replace_dialog);
|
||||
last_search_data_restore_position (XED_SEARCH_DIALOG (replace_dialog));
|
||||
xed_search_dialog_present_with_time (XED_SEARCH_DIALOG (replace_dialog),
|
||||
GDK_CURRENT_TIME);
|
||||
}
|
||||
|
||||
static void
|
||||
do_find_again (XedWindow *window,
|
||||
gboolean backward)
|
||||
{
|
||||
XedView *active_view;
|
||||
gboolean wrap_around = TRUE;
|
||||
gpointer data;
|
||||
|
||||
active_view = xed_window_get_active_view (window);
|
||||
g_return_if_fail (active_view != NULL);
|
||||
|
||||
data = g_object_get_data (G_OBJECT (window), XED_SEARCH_DIALOG_KEY);
|
||||
|
||||
if (data != NULL)
|
||||
wrap_around = xed_search_dialog_get_wrap_around (XED_SEARCH_DIALOG (data));
|
||||
|
||||
run_search (active_view,
|
||||
wrap_around,
|
||||
backward);
|
||||
xed_debug (DEBUG_COMMANDS);
|
||||
xed_searchbar_find_again (xed_window_get_searchbar (window), FALSE);
|
||||
}
|
||||
|
||||
void
|
||||
_xed_cmd_search_find_next (GtkAction *action,
|
||||
XedWindow *window)
|
||||
_xed_cmd_search_find_prev (GtkAction *action, XedWindow *window)
|
||||
{
|
||||
xed_debug (DEBUG_COMMANDS);
|
||||
|
||||
do_find_again (window, FALSE);
|
||||
xed_debug (DEBUG_COMMANDS);
|
||||
xed_searchbar_find_again (xed_window_get_searchbar (window), TRUE);
|
||||
}
|
||||
|
||||
void
|
||||
_xed_cmd_search_find_prev (GtkAction *action,
|
||||
XedWindow *window)
|
||||
_xed_cmd_search_clear_highlight (XedWindow *window)
|
||||
{
|
||||
xed_debug (DEBUG_COMMANDS);
|
||||
|
||||
do_find_again (window, TRUE);
|
||||
XedDocument *doc;
|
||||
xed_debug (DEBUG_COMMANDS);
|
||||
doc = xed_window_get_active_document (window);
|
||||
if (doc != NULL) {
|
||||
xed_document_set_search_text (XED_DOCUMENT (doc), "", XED_SEARCH_DONT_SET_FLAGS);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
_xed_cmd_search_clear_highlight (GtkAction *action,
|
||||
XedWindow *window)
|
||||
_xed_cmd_search_goto_line (GtkAction *action, XedWindow *window)
|
||||
{
|
||||
XedDocument *doc;
|
||||
XedView *active_view;
|
||||
xed_debug (DEBUG_COMMANDS);
|
||||
|
||||
xed_debug (DEBUG_COMMANDS);
|
||||
active_view = xed_window_get_active_view (window);
|
||||
if (active_view == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
doc = xed_window_get_active_document (window);
|
||||
xed_document_set_search_text (XED_DOCUMENT (doc),
|
||||
"",
|
||||
XED_SEARCH_DONT_SET_FLAGS);
|
||||
}
|
||||
|
||||
void
|
||||
_xed_cmd_search_goto_line (GtkAction *action,
|
||||
XedWindow *window)
|
||||
{
|
||||
XedView *active_view;
|
||||
|
||||
xed_debug (DEBUG_COMMANDS);
|
||||
|
||||
active_view = xed_window_get_active_view (window);
|
||||
if (active_view == NULL)
|
||||
return;
|
||||
|
||||
/* Focus the view if needed: we need to focus the view otherwise
|
||||
activating the binding for goto line has no effect */
|
||||
gtk_widget_grab_focus (GTK_WIDGET (active_view));
|
||||
|
||||
|
||||
/* goto line is builtin in XedView, just activate
|
||||
* the corrisponding binding.
|
||||
*/
|
||||
gtk_bindings_activate (G_OBJECT (active_view),
|
||||
GDK_KEY_i,
|
||||
GDK_CONTROL_MASK);
|
||||
}
|
||||
|
||||
void
|
||||
_xed_cmd_search_incremental_search (GtkAction *action,
|
||||
XedWindow *window)
|
||||
{
|
||||
XedView *active_view;
|
||||
|
||||
xed_debug (DEBUG_COMMANDS);
|
||||
|
||||
active_view = xed_window_get_active_view (window);
|
||||
if (active_view == NULL)
|
||||
return;
|
||||
|
||||
/* Focus the view if needed: we need to focus the view otherwise
|
||||
activating the binding for incremental search has no effect */
|
||||
gtk_widget_grab_focus (GTK_WIDGET (active_view));
|
||||
|
||||
/* incremental search is builtin in XedView, just activate
|
||||
* the corrisponding binding.
|
||||
*/
|
||||
gtk_bindings_activate (G_OBJECT (active_view),
|
||||
GDK_KEY_k,
|
||||
GDK_CONTROL_MASK);
|
||||
/* Focus the view if needed: we need to focus the view otherwise
|
||||
activating the binding for goto line has no effect */
|
||||
gtk_widget_grab_focus (GTK_WIDGET (active_view));
|
||||
|
||||
|
||||
/* Goto line is builtin in XedView, just activate the corresponding binding. */
|
||||
gtk_bindings_activate (G_OBJECT (active_view), GDK_KEY_i, GDK_CONTROL_MASK);
|
||||
}
|
||||
|
|
|
@ -1,36 +1,3 @@
|
|||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
|
||||
/*
|
||||
* xed-commands.h
|
||||
* This file is part of xed
|
||||
*
|
||||
* Copyright (C) 1998, 1999 Alex Roberts, Evan Lawrence
|
||||
* Copyright (C) 2000, 2001 Chema Celorio, Paolo Maggi
|
||||
* 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 of the License, 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., 51 Franklin St, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Modified by the xed Team, 1998-2005. See the AUTHORS file for a
|
||||
* list of people on the xed Team.
|
||||
* See the ChangeLog files for a list of changes.
|
||||
*
|
||||
* $Id$
|
||||
*/
|
||||
|
||||
#ifndef __XED_COMMANDS_H__
|
||||
#define __XED_COMMANDS_H__
|
||||
|
||||
|
@ -40,119 +7,66 @@
|
|||
G_BEGIN_DECLS
|
||||
|
||||
/* Do nothing if URI does not exist */
|
||||
void xed_commands_load_uri (XedWindow *window,
|
||||
const gchar *uri,
|
||||
const XedEncoding *encoding,
|
||||
gint line_pos);
|
||||
void xed_commands_load_uri (XedWindow *window, const gchar *uri, const XedEncoding *encoding, gint line_pos);
|
||||
|
||||
/* Ignore non-existing URIs */
|
||||
gint xed_commands_load_uris (XedWindow *window,
|
||||
const GSList *uris,
|
||||
const XedEncoding *encoding,
|
||||
gint line_pos);
|
||||
|
||||
void xed_commands_save_document (XedWindow *window,
|
||||
XedDocument *document);
|
||||
|
||||
void xed_commands_save_all_documents (XedWindow *window);
|
||||
gint xed_commands_load_uris (XedWindow *window, const GSList *uris, const XedEncoding *encoding, gint line_pos);
|
||||
void xed_commands_save_document (XedWindow *window, XedDocument *document);
|
||||
void xed_commands_save_all_documents (XedWindow *window);
|
||||
|
||||
/*
|
||||
* Non-exported functions
|
||||
*/
|
||||
|
||||
/* Create titled documens for non-existing URIs */
|
||||
gint _xed_cmd_load_files_from_prompt (XedWindow *window,
|
||||
GSList *files,
|
||||
const XedEncoding *encoding,
|
||||
gint line_pos);
|
||||
gint _xed_cmd_load_files_from_prompt (XedWindow *window, GSList *files, const XedEncoding *encoding, gint line_pos);
|
||||
void _xed_cmd_file_new (GtkAction *action, XedWindow *window);
|
||||
void _xed_cmd_file_open (GtkAction *action, XedWindow *window);
|
||||
void _xed_cmd_file_save (GtkAction *action, XedWindow *window);
|
||||
void _xed_cmd_file_save_as (GtkAction *action, XedWindow *window);
|
||||
void _xed_cmd_file_save_all (GtkAction *action, XedWindow *window);
|
||||
void _xed_cmd_file_revert (GtkAction *action, XedWindow *window);
|
||||
void _xed_cmd_file_open_uri (GtkAction *action, XedWindow *window);
|
||||
void _xed_cmd_file_print_preview (GtkAction *action, XedWindow *window);
|
||||
void _xed_cmd_file_print (GtkAction *action, XedWindow *window);
|
||||
void _xed_cmd_file_close (GtkAction *action, XedWindow *window);
|
||||
void _xed_cmd_file_close_all (GtkAction *action, XedWindow *window);
|
||||
void _xed_cmd_file_quit (GtkAction *action, XedWindow *window);
|
||||
|
||||
void _xed_cmd_file_new (GtkAction *action,
|
||||
XedWindow *window);
|
||||
void _xed_cmd_file_open (GtkAction *action,
|
||||
XedWindow *window);
|
||||
void _xed_cmd_file_save (GtkAction *action,
|
||||
XedWindow *window);
|
||||
void _xed_cmd_file_save_as (GtkAction *action,
|
||||
XedWindow *window);
|
||||
void _xed_cmd_file_save_all (GtkAction *action,
|
||||
XedWindow *window);
|
||||
void _xed_cmd_file_revert (GtkAction *action,
|
||||
XedWindow *window);
|
||||
void _xed_cmd_file_open_uri (GtkAction *action,
|
||||
XedWindow *window);
|
||||
void _xed_cmd_file_print_preview (GtkAction *action,
|
||||
XedWindow *window);
|
||||
void _xed_cmd_file_print (GtkAction *action,
|
||||
XedWindow *window);
|
||||
void _xed_cmd_file_close (GtkAction *action,
|
||||
XedWindow *window);
|
||||
void _xed_cmd_file_close_all (GtkAction *action,
|
||||
XedWindow *window);
|
||||
void _xed_cmd_file_quit (GtkAction *action,
|
||||
XedWindow *window);
|
||||
void _xed_cmd_edit_undo (GtkAction *action, XedWindow *window);
|
||||
void _xed_cmd_edit_redo (GtkAction *action, XedWindow *window);
|
||||
void _xed_cmd_edit_cut (GtkAction *action, XedWindow *window);
|
||||
void _xed_cmd_edit_copy (GtkAction *action, XedWindow *window);
|
||||
void _xed_cmd_edit_paste (GtkAction *action, XedWindow *window);
|
||||
void _xed_cmd_edit_delete (GtkAction *action, XedWindow *window);
|
||||
void _xed_cmd_edit_select_all (GtkAction *action, XedWindow *window);
|
||||
void _xed_cmd_edit_preferences (GtkAction *action, XedWindow *window);
|
||||
|
||||
void _xed_cmd_edit_undo (GtkAction *action,
|
||||
XedWindow *window);
|
||||
void _xed_cmd_edit_redo (GtkAction *action,
|
||||
XedWindow *window);
|
||||
void _xed_cmd_edit_cut (GtkAction *action,
|
||||
XedWindow *window);
|
||||
void _xed_cmd_edit_copy (GtkAction *action,
|
||||
XedWindow *window);
|
||||
void _xed_cmd_edit_paste (GtkAction *action,
|
||||
XedWindow *window);
|
||||
void _xed_cmd_edit_delete (GtkAction *action,
|
||||
XedWindow *window);
|
||||
void _xed_cmd_edit_select_all (GtkAction *action,
|
||||
XedWindow *window);
|
||||
void _xed_cmd_edit_preferences (GtkAction *action,
|
||||
XedWindow *window);
|
||||
void _xed_cmd_view_show_toolbar (GtkAction *action, XedWindow *window);
|
||||
void _xed_cmd_view_show_statusbar (GtkAction *action, XedWindow *window);
|
||||
void _xed_cmd_view_show_side_pane (GtkAction *action, XedWindow *window);
|
||||
void _xed_cmd_view_show_bottom_pane (GtkAction *action, XedWindow *window);
|
||||
void _xed_cmd_view_toggle_fullscreen_mode (GtkAction *action, XedWindow *window);
|
||||
void _xed_cmd_view_leave_fullscreen_mode (GtkAction *action, XedWindow *window);
|
||||
|
||||
void _xed_cmd_view_show_toolbar (GtkAction *action,
|
||||
XedWindow *window);
|
||||
void _xed_cmd_view_show_statusbar (GtkAction *action,
|
||||
XedWindow *window);
|
||||
void _xed_cmd_view_show_side_pane (GtkAction *action,
|
||||
XedWindow *window);
|
||||
void _xed_cmd_view_show_bottom_pane (GtkAction *action,
|
||||
XedWindow *window);
|
||||
void _xed_cmd_view_toggle_fullscreen_mode (GtkAction *action,
|
||||
XedWindow *window);
|
||||
void _xed_cmd_view_leave_fullscreen_mode (GtkAction *action,
|
||||
XedWindow *window);
|
||||
void _xed_cmd_search_find (GtkAction *action, XedWindow *window);
|
||||
|
||||
void _xed_cmd_search_find (GtkAction *action,
|
||||
XedWindow *window);
|
||||
void _xed_cmd_search_find_next (GtkAction *action,
|
||||
XedWindow *window);
|
||||
void _xed_cmd_search_find_prev (GtkAction *action,
|
||||
XedWindow *window);
|
||||
void _xed_cmd_search_replace (GtkAction *action,
|
||||
XedWindow *window);
|
||||
void _xed_cmd_search_clear_highlight (GtkAction *action,
|
||||
XedWindow *window);
|
||||
void _xed_cmd_search_goto_line (GtkAction *action,
|
||||
XedWindow *window);
|
||||
void _xed_cmd_search_incremental_search (GtkAction *action,
|
||||
XedWindow *window);
|
||||
void _xed_cmd_search_find_next (GtkAction *action, XedWindow *window);
|
||||
void _xed_cmd_search_find_prev (GtkAction *action, XedWindow *window);
|
||||
void _xed_cmd_search_replace (GtkAction *action, XedWindow *window);
|
||||
void _xed_cmd_search_clear_highlight (XedWindow *window);
|
||||
void _xed_cmd_search_goto_line (GtkAction *action, XedWindow *window);
|
||||
|
||||
void _xed_cmd_documents_previous_document (GtkAction *action,
|
||||
XedWindow *window);
|
||||
void _xed_cmd_documents_next_document (GtkAction *action,
|
||||
XedWindow *window);
|
||||
void _xed_cmd_documents_move_to_new_window (GtkAction *action,
|
||||
XedWindow *window);
|
||||
void _xed_cmd_documents_previous_document (GtkAction *action, XedWindow *window);
|
||||
void _xed_cmd_documents_next_document (GtkAction *action, XedWindow *window);
|
||||
void _xed_cmd_documents_move_to_new_window (GtkAction *action, XedWindow *window);
|
||||
|
||||
void _xed_cmd_help_contents (GtkAction *action,
|
||||
XedWindow *window);
|
||||
void _xed_cmd_help_about (GtkAction *action,
|
||||
XedWindow *window);
|
||||
void _xed_cmd_help_contents (GtkAction *action, XedWindow *window);
|
||||
void _xed_cmd_help_about (GtkAction *action, XedWindow *window);
|
||||
|
||||
void _xed_cmd_file_close_tab (XedTab *tab,
|
||||
XedWindow *window);
|
||||
void _xed_cmd_file_close_tab (XedTab *tab, XedWindow *window);
|
||||
|
||||
void _xed_cmd_file_save_documents_list (XedWindow *window,
|
||||
GList *docs);
|
||||
void _xed_cmd_file_save_documents_list (XedWindow *window, GList *docs);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
|
|
|
@ -0,0 +1,719 @@
|
|||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
#include <glib/gi18n.h>
|
||||
#include <gtk/gtk.h>
|
||||
#include <gdk/gdkkeysyms.h>
|
||||
|
||||
#include "xed-searchbar.h"
|
||||
#include "xed-statusbar.h"
|
||||
#include "xed-history-entry.h"
|
||||
#include "xed-utils.h"
|
||||
#include "xed-marshal.h"
|
||||
#include "xed-dirs.h"
|
||||
#include "xed-commands.h"
|
||||
#include "xed-window-private.h"
|
||||
|
||||
#define XED_SEARCHBAR_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), XED_TYPE_SEARCHBAR, XedSearchbarPrivate))
|
||||
|
||||
/* Signals */
|
||||
enum
|
||||
{
|
||||
SHOW_REPLACE,
|
||||
LAST_SIGNAL
|
||||
};
|
||||
|
||||
struct _XedSearchbarPrivate
|
||||
{
|
||||
gboolean show_replace;
|
||||
GtkWidget *revealer;
|
||||
GtkWidget *grid;
|
||||
GtkWidget *search_label;
|
||||
GtkWidget *search_entry;
|
||||
GtkWidget *search_text_entry;
|
||||
GtkWidget *replace_label;
|
||||
GtkWidget *replace_entry;
|
||||
GtkWidget *replace_text_entry;
|
||||
GtkWidget *match_case_checkbutton;
|
||||
GtkWidget *entire_word_checkbutton;
|
||||
GtkWidget *wrap_around_checkbutton;
|
||||
GtkWidget *find_button;
|
||||
GtkWidget *find_prev_button;
|
||||
GtkWidget *replace_button;
|
||||
GtkWidget *replace_all_button;
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE(XedSearchbar, xed_searchbar, GTK_TYPE_BOX)
|
||||
|
||||
static void
|
||||
xed_searchbar_class_init (XedSearchbarClass *klass)
|
||||
{
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
||||
GtkBindingSet *binding_set;
|
||||
g_type_class_add_private (object_class, sizeof (XedSearchbarPrivate));
|
||||
binding_set = gtk_binding_set_by_class (klass);
|
||||
}
|
||||
|
||||
#define XED_SEARCHBAR_KEY "xed-searchbar-key"
|
||||
#define MAX_MSG_LENGTH 40
|
||||
|
||||
/* Use occurrences only for Replace All */
|
||||
static void
|
||||
text_found (XedWindow *window, gint occurrences)
|
||||
{
|
||||
if (occurrences > 1) {
|
||||
xed_statusbar_flash_message (XED_STATUSBAR (window->priv->statusbar),
|
||||
window->priv->generic_message_cid,
|
||||
ngettext("Found and replaced %d occurrence",
|
||||
"Found and replaced %d occurrences",
|
||||
occurrences),
|
||||
occurrences);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (occurrences == 1) {
|
||||
xed_statusbar_flash_message (XED_STATUSBAR (window->priv->statusbar),
|
||||
window->priv->generic_message_cid,
|
||||
_("Found and replaced one occurrence"));
|
||||
}
|
||||
else {
|
||||
xed_statusbar_flash_message (XED_STATUSBAR (window->priv->statusbar),
|
||||
window->priv->generic_message_cid,
|
||||
" ");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
text_not_found (XedWindow *window, const gchar *text)
|
||||
{
|
||||
gchar *searched;
|
||||
|
||||
searched = xed_utils_str_end_truncate (text, MAX_MSG_LENGTH);
|
||||
xed_statusbar_flash_message (XED_STATUSBAR (window->priv->statusbar),
|
||||
window->priv->generic_message_cid,
|
||||
_("\"%s\" not found"), searched);
|
||||
g_free (searched);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
run_search (XedView *view, gboolean wrap_around, gboolean search_backwards)
|
||||
{
|
||||
XedDocument *doc;
|
||||
GtkTextIter start_iter;
|
||||
GtkTextIter match_start;
|
||||
GtkTextIter match_end;
|
||||
gboolean found = FALSE;
|
||||
|
||||
doc = XED_DOCUMENT (gtk_text_view_get_buffer (GTK_TEXT_VIEW (view)));
|
||||
|
||||
if (!search_backwards) {
|
||||
gtk_text_buffer_get_selection_bounds (GTK_TEXT_BUFFER (doc), NULL, &start_iter);
|
||||
found = xed_document_search_forward (doc, &start_iter, NULL, &match_start, &match_end);
|
||||
}
|
||||
else {
|
||||
gtk_text_buffer_get_selection_bounds (GTK_TEXT_BUFFER (doc), &start_iter, NULL);
|
||||
found = xed_document_search_backward (doc, NULL, &start_iter, &match_start, &match_end);
|
||||
}
|
||||
|
||||
if (!found && wrap_around) {
|
||||
if (!search_backwards) {
|
||||
found = xed_document_search_forward (doc, NULL, NULL, /* FIXME: set the end_inter */
|
||||
&match_start, &match_end);
|
||||
}
|
||||
else {
|
||||
found = xed_document_search_backward (doc, NULL, /* FIXME: set the start_inter */ NULL,
|
||||
&match_start, &match_end);
|
||||
}
|
||||
}
|
||||
|
||||
if (found) {
|
||||
gtk_text_buffer_place_cursor (GTK_TEXT_BUFFER (doc), &match_start);
|
||||
gtk_text_buffer_move_mark_by_name (GTK_TEXT_BUFFER (doc), "selection_bound", &match_end);
|
||||
xed_view_scroll_to_cursor (view);
|
||||
}
|
||||
else {
|
||||
gtk_text_buffer_place_cursor (GTK_TEXT_BUFFER (doc), &start_iter);
|
||||
}
|
||||
|
||||
return found;
|
||||
}
|
||||
|
||||
static void
|
||||
do_find (XedSearchbar *searchbar, gboolean search_backwards)
|
||||
{
|
||||
XedView *active_view;
|
||||
XedDocument *doc;
|
||||
gchar *search_text;
|
||||
const gchar *entry_text;
|
||||
gboolean match_case;
|
||||
gboolean entire_word;
|
||||
gboolean wrap_around;
|
||||
guint flags = 0;
|
||||
guint old_flags = 0;
|
||||
gboolean found;
|
||||
|
||||
/* TODO: make the searchbar insensitive when all the tabs are closed
|
||||
* and assert here that the view is not NULL */
|
||||
active_view = xed_window_get_active_view (searchbar->window);
|
||||
if (active_view == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
doc = XED_DOCUMENT (gtk_text_view_get_buffer (GTK_TEXT_VIEW (active_view)));
|
||||
|
||||
match_case = xed_searchbar_get_match_case (searchbar);
|
||||
entire_word = xed_searchbar_get_entire_word (searchbar);
|
||||
wrap_around = xed_searchbar_get_wrap_around (searchbar);
|
||||
entry_text = xed_searchbar_get_search_text (searchbar);
|
||||
|
||||
XED_SEARCH_SET_CASE_SENSITIVE (flags, match_case);
|
||||
XED_SEARCH_SET_ENTIRE_WORD (flags, entire_word);
|
||||
|
||||
search_text = xed_document_get_search_text (doc, &old_flags);
|
||||
|
||||
if ((search_text == NULL) || (strcmp (search_text, entry_text) != 0) || (flags != old_flags)) {
|
||||
xed_document_set_search_text (doc, entry_text, flags);
|
||||
}
|
||||
|
||||
g_free (search_text);
|
||||
|
||||
found = run_search (active_view, wrap_around, search_backwards);
|
||||
|
||||
if (found) {
|
||||
text_found (searchbar->window, 0);
|
||||
}
|
||||
else {
|
||||
text_not_found (searchbar->window, entry_text);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
xed_searchbar_find_again (XedSearchbar *searchbar, gboolean backward)
|
||||
{
|
||||
XedView *active_view;
|
||||
gboolean wrap_around = TRUE;
|
||||
gpointer data;
|
||||
|
||||
active_view = xed_window_get_active_view (searchbar->window);
|
||||
g_return_if_fail (active_view != NULL);
|
||||
|
||||
data = g_object_get_data (G_OBJECT (searchbar->window), XED_SEARCHBAR_KEY);
|
||||
|
||||
if (data != NULL) {
|
||||
wrap_around = xed_searchbar_get_wrap_around (XED_SEARCHBAR (data));
|
||||
}
|
||||
|
||||
run_search (active_view, wrap_around, backward);
|
||||
}
|
||||
|
||||
static void
|
||||
search_buttons_set_sensitive (XedSearchbar *searchbar, gboolean sensitive)
|
||||
{
|
||||
gtk_widget_set_sensitive (searchbar->priv->find_button, sensitive);
|
||||
gtk_widget_set_sensitive (searchbar->priv->find_prev_button, sensitive);
|
||||
gtk_widget_set_sensitive (searchbar->priv->replace_button, sensitive);
|
||||
gtk_widget_set_sensitive (searchbar->priv->replace_all_button, sensitive);
|
||||
}
|
||||
|
||||
/* FIXME: move in xed-document.c and share it with xed-view */
|
||||
static gboolean
|
||||
get_selected_text (GtkTextBuffer *doc, gchar **selected_text, gint *len)
|
||||
{
|
||||
GtkTextIter start, end;
|
||||
|
||||
g_return_val_if_fail (selected_text != NULL, FALSE);
|
||||
g_return_val_if_fail (*selected_text == NULL, FALSE);
|
||||
|
||||
if (!gtk_text_buffer_get_selection_bounds (doc, &start, &end)) {
|
||||
if (len != NULL) {
|
||||
len = 0;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
*selected_text = gtk_text_buffer_get_slice (doc, &start, &end, TRUE);
|
||||
|
||||
if (len != NULL) {
|
||||
*len = g_utf8_strlen (*selected_text, -1);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
replace_selected_text (GtkTextBuffer *buffer, const gchar *replace)
|
||||
{
|
||||
g_return_if_fail (gtk_text_buffer_get_selection_bounds (buffer, NULL, NULL));
|
||||
g_return_if_fail (replace != NULL);
|
||||
|
||||
gtk_text_buffer_begin_user_action (buffer);
|
||||
gtk_text_buffer_delete_selection (buffer, FALSE, TRUE);
|
||||
gtk_text_buffer_insert_at_cursor (buffer, replace, strlen (replace));
|
||||
gtk_text_buffer_end_user_action (buffer);
|
||||
}
|
||||
|
||||
static void
|
||||
do_replace (XedSearchbar *searchbar)
|
||||
{
|
||||
XedDocument *doc;
|
||||
const gchar *search_entry_text;
|
||||
const gchar *replace_entry_text;
|
||||
gchar *unescaped_search_text;
|
||||
gchar *unescaped_replace_text;
|
||||
gchar *selected_text = NULL;
|
||||
gboolean match_case;
|
||||
|
||||
doc = xed_window_get_active_document (searchbar->window);
|
||||
if (doc == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
search_entry_text = xed_searchbar_get_search_text (searchbar);
|
||||
g_return_if_fail ((search_entry_text) != NULL);
|
||||
g_return_if_fail ((*search_entry_text) != '\0');
|
||||
|
||||
/* replace text may be "", we just delete */
|
||||
replace_entry_text = xed_searchbar_get_replace_text (searchbar);
|
||||
g_return_if_fail ((replace_entry_text) != NULL);
|
||||
|
||||
unescaped_search_text = xed_utils_unescape_search_text (search_entry_text);
|
||||
|
||||
get_selected_text (GTK_TEXT_BUFFER (doc), &selected_text, NULL);
|
||||
|
||||
match_case = xed_searchbar_get_match_case (searchbar);
|
||||
|
||||
if ((selected_text == NULL) ||
|
||||
(match_case && (strcmp (selected_text, unescaped_search_text) != 0)) ||
|
||||
(!match_case && !g_utf8_caselessnmatch (selected_text,
|
||||
unescaped_search_text,
|
||||
strlen (selected_text),
|
||||
strlen (unescaped_search_text)) != 0)) {
|
||||
do_find (searchbar, FALSE);
|
||||
g_free (unescaped_search_text);
|
||||
g_free (selected_text);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
unescaped_replace_text = xed_utils_unescape_search_text (replace_entry_text);
|
||||
replace_selected_text (GTK_TEXT_BUFFER (doc), unescaped_replace_text);
|
||||
|
||||
g_free (unescaped_search_text);
|
||||
g_free (selected_text);
|
||||
g_free (unescaped_replace_text);
|
||||
|
||||
do_find (searchbar, FALSE);
|
||||
}
|
||||
|
||||
static void
|
||||
do_replace_all (XedSearchbar *searchbar)
|
||||
{
|
||||
XedView *active_view;
|
||||
XedDocument *doc;
|
||||
const gchar *search_entry_text;
|
||||
const gchar *replace_entry_text;
|
||||
gboolean match_case;
|
||||
gboolean entire_word;
|
||||
guint flags = 0;
|
||||
gint count;
|
||||
|
||||
active_view = xed_window_get_active_view (searchbar->window);
|
||||
if (active_view == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
doc = XED_DOCUMENT (gtk_text_view_get_buffer (GTK_TEXT_VIEW (active_view)));
|
||||
|
||||
search_entry_text = xed_searchbar_get_search_text (searchbar);
|
||||
g_return_if_fail ((search_entry_text) != NULL);
|
||||
g_return_if_fail ((*search_entry_text) != '\0');
|
||||
|
||||
/* replace text may be "", we just delete all occurrences */
|
||||
replace_entry_text = xed_searchbar_get_replace_text (searchbar);
|
||||
g_return_if_fail ((replace_entry_text) != NULL);
|
||||
|
||||
match_case = xed_searchbar_get_match_case (searchbar);
|
||||
entire_word = xed_searchbar_get_entire_word (searchbar);
|
||||
|
||||
XED_SEARCH_SET_CASE_SENSITIVE (flags, match_case);
|
||||
XED_SEARCH_SET_ENTIRE_WORD (flags, entire_word);
|
||||
|
||||
count = xed_document_replace_all (doc, search_entry_text, replace_entry_text, flags);
|
||||
|
||||
if (count > 0) {
|
||||
text_found (searchbar->window, count);
|
||||
}
|
||||
else {
|
||||
text_not_found (searchbar->window, search_entry_text);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static void
|
||||
insert_text_handler (GtkEditable *editable, const gchar *text, gint length, gint *position, gpointer data)
|
||||
{
|
||||
static gboolean insert_text = FALSE;
|
||||
gchar *escaped_text;
|
||||
gint new_len;
|
||||
|
||||
/* To avoid recursive behavior */
|
||||
if (insert_text) {
|
||||
return;
|
||||
}
|
||||
|
||||
escaped_text = xed_utils_escape_search_text (text);
|
||||
|
||||
new_len = strlen (escaped_text);
|
||||
|
||||
if (new_len == length) {
|
||||
g_free (escaped_text);
|
||||
return;
|
||||
}
|
||||
|
||||
insert_text = TRUE;
|
||||
|
||||
g_signal_stop_emission_by_name (editable, "insert_text");
|
||||
|
||||
gtk_editable_insert_text (editable, escaped_text, new_len, position);
|
||||
|
||||
insert_text = FALSE;
|
||||
|
||||
g_free (escaped_text);
|
||||
}
|
||||
|
||||
static void
|
||||
search_text_entry_changed (GtkEditable *editable, XedSearchbar *searchbar)
|
||||
{
|
||||
const gchar *search_string;
|
||||
|
||||
search_string = gtk_entry_get_text (GTK_ENTRY (editable));
|
||||
g_return_if_fail (search_string != NULL);
|
||||
|
||||
if (*search_string != '\0') {
|
||||
search_buttons_set_sensitive(searchbar, TRUE);
|
||||
do_find (searchbar, FALSE);
|
||||
}
|
||||
else {
|
||||
search_buttons_set_sensitive(searchbar, FALSE);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
remember_search_entry (XedSearchbar *searchbar)
|
||||
{
|
||||
const gchar *str;
|
||||
str = gtk_entry_get_text (GTK_ENTRY (searchbar->priv->search_text_entry));
|
||||
if (*str != '\0') {
|
||||
gchar *text;
|
||||
text = xed_utils_unescape_search_text (str);
|
||||
xed_history_entry_prepend_text (XED_HISTORY_ENTRY (searchbar->priv->search_entry), text);
|
||||
g_free (text);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
remember_replace_entry (XedSearchbar *searchbar)
|
||||
{
|
||||
const gchar *str;
|
||||
str = gtk_entry_get_text (GTK_ENTRY (searchbar->priv->replace_text_entry));
|
||||
if (*str != '\0') {
|
||||
gchar *text;
|
||||
text = xed_utils_unescape_search_text (str);
|
||||
xed_history_entry_prepend_text (XED_HISTORY_ENTRY (searchbar->priv->replace_entry), text);
|
||||
g_free (text);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
find_button_clicked_callback (GtkWidget *button, XedSearchbar *searchbar)
|
||||
{
|
||||
remember_search_entry (searchbar);
|
||||
do_find (searchbar, FALSE);
|
||||
}
|
||||
|
||||
static void
|
||||
find_prev_button_clicked_callback (GtkWidget *button, XedSearchbar *searchbar)
|
||||
{
|
||||
remember_search_entry (searchbar);
|
||||
do_find (searchbar, TRUE);
|
||||
}
|
||||
|
||||
static void
|
||||
replace_button_clicked_callback (GtkWidget *button, XedSearchbar *searchbar)
|
||||
{
|
||||
remember_search_entry (searchbar);
|
||||
remember_replace_entry (searchbar);
|
||||
do_replace (searchbar);
|
||||
}
|
||||
|
||||
static void
|
||||
replace_all_button_clicked_callback (GtkWidget *button, XedSearchbar *searchbar)
|
||||
{
|
||||
remember_search_entry (searchbar);
|
||||
remember_replace_entry (searchbar);
|
||||
do_replace_all (searchbar);
|
||||
}
|
||||
|
||||
static void
|
||||
on_search_text_entry_activated (GtkEntry *widget, XedSearchbar *searchbar)
|
||||
{
|
||||
remember_search_entry (searchbar);
|
||||
do_find (searchbar, FALSE);
|
||||
}
|
||||
|
||||
static void
|
||||
xed_searchbar_init (XedSearchbar *searchbar)
|
||||
{
|
||||
GtkWidget *content;
|
||||
GtkSizeGroup *size_group;
|
||||
GtkWidget *error_widget;
|
||||
gchar *file;
|
||||
gchar *root_objects[] = {"searchbar_content", NULL};
|
||||
|
||||
searchbar->priv = XED_SEARCHBAR_GET_PRIVATE (searchbar);
|
||||
|
||||
file = xed_dirs_get_ui_file ("xed-searchbar.ui");
|
||||
xed_utils_get_ui_objects (file,
|
||||
root_objects,
|
||||
&error_widget,
|
||||
"searchbar_content", &content,
|
||||
"revealer", &searchbar->priv->revealer,
|
||||
"grid", &searchbar->priv->grid,
|
||||
"search_label", &searchbar->priv->search_label,
|
||||
"replace_with_label", &searchbar->priv->replace_label,
|
||||
"match_case_checkbutton", &searchbar->priv->match_case_checkbutton,
|
||||
"entire_word_checkbutton", &searchbar->priv->entire_word_checkbutton,
|
||||
"wrap_around_checkbutton", &searchbar->priv->wrap_around_checkbutton,
|
||||
"find_button", &searchbar->priv->find_button,
|
||||
"find_prev_button", &searchbar->priv->find_prev_button,
|
||||
"replace_button", &searchbar->priv->replace_button,
|
||||
"replace_all_button", &searchbar->priv->replace_all_button,
|
||||
NULL);
|
||||
g_free (file);
|
||||
|
||||
searchbar->priv->search_entry = xed_history_entry_new ("history-search-for", TRUE);
|
||||
gtk_widget_set_hexpand (searchbar->priv->search_entry, TRUE);
|
||||
xed_history_entry_set_escape_func (
|
||||
XED_HISTORY_ENTRY (searchbar->priv->search_entry),
|
||||
(XedHistoryEntryEscapeFunc) xed_utils_escape_search_text);
|
||||
|
||||
searchbar->priv->search_text_entry = xed_history_entry_get_entry (
|
||||
XED_HISTORY_ENTRY (searchbar->priv->search_entry));
|
||||
gtk_entry_set_activates_default (GTK_ENTRY (searchbar->priv->search_text_entry), TRUE);
|
||||
|
||||
gtk_widget_show (searchbar->priv->search_entry);
|
||||
gtk_grid_attach (GTK_GRID (searchbar->priv->grid), searchbar->priv->search_entry, 2, 0, 1, 1);
|
||||
|
||||
searchbar->priv->replace_entry = xed_history_entry_new ("history-replace-with", TRUE);
|
||||
xed_history_entry_set_escape_func (
|
||||
XED_HISTORY_ENTRY (searchbar->priv->replace_entry),
|
||||
(XedHistoryEntryEscapeFunc) xed_utils_escape_search_text);
|
||||
|
||||
searchbar->priv->replace_text_entry = xed_history_entry_get_entry (
|
||||
XED_HISTORY_ENTRY (searchbar->priv->replace_entry));
|
||||
gtk_entry_set_activates_default (GTK_ENTRY (searchbar->priv->replace_text_entry), TRUE);
|
||||
|
||||
gtk_widget_show (searchbar->priv->replace_entry);
|
||||
gtk_grid_attach (GTK_GRID (searchbar->priv->grid), searchbar->priv->replace_entry, 2, 1, 1, 1);
|
||||
|
||||
gtk_label_set_mnemonic_widget (GTK_LABEL (searchbar->priv->search_label), searchbar->priv->search_entry);
|
||||
gtk_label_set_mnemonic_widget (GTK_LABEL (searchbar->priv->replace_label), searchbar->priv->replace_entry);
|
||||
|
||||
size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
|
||||
gtk_size_group_add_widget (size_group, GTK_WIDGET (searchbar->priv->find_button));
|
||||
gtk_size_group_add_widget (size_group, GTK_WIDGET (searchbar->priv->find_prev_button));
|
||||
gtk_size_group_add_widget (size_group, GTK_WIDGET (searchbar->priv->replace_button));
|
||||
gtk_size_group_add_widget (size_group, GTK_WIDGET (searchbar->priv->replace_all_button));
|
||||
|
||||
/* insensitive by default */
|
||||
search_buttons_set_sensitive(searchbar, FALSE);
|
||||
|
||||
xed_searchbar_hide (searchbar);
|
||||
|
||||
gtk_box_pack_start (GTK_BOX (searchbar), content, TRUE, TRUE, 0);
|
||||
gtk_widget_show (GTK_WIDGET (searchbar));
|
||||
|
||||
g_object_unref (content);
|
||||
|
||||
g_signal_connect (searchbar->priv->search_text_entry, "insert_text",
|
||||
G_CALLBACK (insert_text_handler), NULL);
|
||||
|
||||
g_signal_connect (searchbar->priv->replace_text_entry, "insert_text",
|
||||
G_CALLBACK (insert_text_handler), NULL);
|
||||
|
||||
g_signal_connect (searchbar->priv->search_text_entry, "changed",
|
||||
G_CALLBACK (search_text_entry_changed), searchbar);
|
||||
|
||||
g_signal_connect (searchbar->priv->search_text_entry, "activate",
|
||||
G_CALLBACK (on_search_text_entry_activated), searchbar);
|
||||
|
||||
g_signal_connect (searchbar->priv->find_button, "clicked",
|
||||
G_CALLBACK (find_button_clicked_callback), searchbar);
|
||||
|
||||
g_signal_connect (searchbar->priv->find_prev_button, "clicked",
|
||||
G_CALLBACK (find_prev_button_clicked_callback), searchbar);
|
||||
|
||||
g_signal_connect (searchbar->priv->replace_button, "clicked",
|
||||
G_CALLBACK (replace_button_clicked_callback), searchbar);
|
||||
|
||||
g_signal_connect (searchbar->priv->replace_all_button, "clicked",
|
||||
G_CALLBACK (replace_all_button_clicked_callback), searchbar);
|
||||
}
|
||||
|
||||
GtkWidget *
|
||||
xed_searchbar_new (GtkWindow *parent, gboolean show_replace)
|
||||
{
|
||||
XedSearchbar *searchbar;
|
||||
searchbar = g_object_new (XED_TYPE_SEARCHBAR, NULL);
|
||||
searchbar->window = parent;
|
||||
return GTK_WIDGET (searchbar);
|
||||
}
|
||||
|
||||
void xed_searchbar_show (XedSearchbar *searchbar, gboolean show_replace)
|
||||
{
|
||||
XedDocument *doc;
|
||||
gboolean selection_exists;
|
||||
gchar *find_text = NULL;
|
||||
const gchar *search_text = NULL;
|
||||
gint sel_len;
|
||||
|
||||
doc = xed_window_get_active_document (searchbar->window);
|
||||
g_return_if_fail (doc != NULL);
|
||||
|
||||
selection_exists = get_selected_text (GTK_TEXT_BUFFER (doc), &find_text, &sel_len);
|
||||
|
||||
if (selection_exists && find_text != NULL && sel_len < 80) {
|
||||
/*
|
||||
* Special case: if the currently selected text
|
||||
* is the same as the unescaped search text, use the
|
||||
* same old search text. (Without this, if you e.g.
|
||||
* search for '\n' and then open the search searchbar again,
|
||||
* you'll get an unprintable single-character literal '\n' in the "search for" box).
|
||||
*/
|
||||
search_text = xed_searchbar_get_search_text (XED_SEARCHBAR (searchbar));
|
||||
if (!(search_text != NULL && !strcmp(xed_utils_unescape_search_text(search_text), find_text))) {
|
||||
/* General case */
|
||||
xed_searchbar_set_search_text (XED_SEARCHBAR (searchbar), find_text);
|
||||
}
|
||||
g_free (find_text);
|
||||
}
|
||||
else {
|
||||
g_free (find_text);
|
||||
}
|
||||
gtk_revealer_set_transition_type (GTK_REVEALER (searchbar->priv->revealer), GTK_REVEALER_TRANSITION_TYPE_SLIDE_UP);
|
||||
gtk_revealer_set_reveal_child (GTK_REVEALER (searchbar->priv->revealer), TRUE);
|
||||
if (show_replace) {
|
||||
gtk_widget_show (searchbar->priv->replace_label);
|
||||
gtk_widget_show (searchbar->priv->replace_entry);
|
||||
gtk_widget_show (searchbar->priv->replace_all_button);
|
||||
gtk_widget_show (searchbar->priv->replace_button);
|
||||
gtk_grid_set_row_spacing (GTK_GRID (searchbar->priv->grid), 10);
|
||||
}
|
||||
else {
|
||||
gtk_widget_hide (searchbar->priv->replace_label);
|
||||
gtk_widget_hide (searchbar->priv->replace_entry);
|
||||
gtk_widget_hide (searchbar->priv->replace_all_button);
|
||||
gtk_widget_hide (searchbar->priv->replace_button);
|
||||
gtk_grid_set_row_spacing (GTK_GRID (searchbar->priv->grid), 0);
|
||||
}
|
||||
|
||||
gtk_widget_show (searchbar->priv->find_button);
|
||||
gtk_widget_grab_focus (searchbar->priv->search_text_entry);
|
||||
}
|
||||
|
||||
void xed_searchbar_hide (XedSearchbar *searchbar)
|
||||
{
|
||||
gtk_revealer_set_transition_type (GTK_REVEALER (searchbar->priv->revealer),
|
||||
GTK_REVEALER_TRANSITION_TYPE_SLIDE_DOWN);
|
||||
gtk_revealer_set_reveal_child (GTK_REVEALER (searchbar->priv->revealer), FALSE);
|
||||
|
||||
// focus document
|
||||
XedView *active_view = xed_window_get_active_view (searchbar->window);
|
||||
if (active_view != NULL) {
|
||||
gtk_widget_grab_focus (GTK_WIDGET (active_view));
|
||||
}
|
||||
|
||||
// remove highlighting
|
||||
_xed_cmd_search_clear_highlight (searchbar->window);
|
||||
}
|
||||
|
||||
void
|
||||
xed_searchbar_set_search_text (XedSearchbar *searchbar, const gchar *text)
|
||||
{
|
||||
g_return_if_fail (XED_IS_SEARCHBAR (searchbar));
|
||||
g_return_if_fail (text != NULL);
|
||||
gtk_entry_set_text (GTK_ENTRY (searchbar->priv->search_text_entry), text);
|
||||
search_buttons_set_sensitive(searchbar, (text != '\0'));
|
||||
}
|
||||
|
||||
/*
|
||||
* The text must be unescaped before searching.
|
||||
*/
|
||||
const gchar *
|
||||
xed_searchbar_get_search_text (XedSearchbar *searchbar)
|
||||
{
|
||||
g_return_val_if_fail (XED_IS_SEARCHBAR (searchbar), NULL);
|
||||
return gtk_entry_get_text (GTK_ENTRY (searchbar->priv->search_text_entry));
|
||||
}
|
||||
|
||||
void
|
||||
xed_searchbar_set_replace_text (XedSearchbar *searchbar, const gchar *text)
|
||||
{
|
||||
g_return_if_fail (XED_IS_SEARCHBAR (searchbar));
|
||||
g_return_if_fail (text != NULL);
|
||||
|
||||
gtk_entry_set_text (GTK_ENTRY (searchbar->priv->replace_text_entry), text);
|
||||
}
|
||||
|
||||
const gchar *
|
||||
xed_searchbar_get_replace_text (XedSearchbar *searchbar)
|
||||
{
|
||||
g_return_val_if_fail (XED_IS_SEARCHBAR (searchbar), NULL);
|
||||
return gtk_entry_get_text (GTK_ENTRY (searchbar->priv->replace_text_entry));
|
||||
}
|
||||
|
||||
void
|
||||
xed_searchbar_set_match_case (XedSearchbar *searchbar, gboolean match_case)
|
||||
{
|
||||
g_return_if_fail (XED_IS_SEARCHBAR (searchbar));
|
||||
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (searchbar->priv->match_case_checkbutton), match_case);
|
||||
}
|
||||
|
||||
gboolean
|
||||
xed_searchbar_get_match_case (XedSearchbar *searchbar)
|
||||
{
|
||||
g_return_val_if_fail (XED_IS_SEARCHBAR (searchbar), FALSE);
|
||||
return gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (searchbar->priv->match_case_checkbutton));
|
||||
}
|
||||
|
||||
void
|
||||
xed_searchbar_set_entire_word (XedSearchbar *searchbar, gboolean entire_word)
|
||||
{
|
||||
g_return_if_fail (XED_IS_SEARCHBAR (searchbar));
|
||||
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (searchbar->priv->entire_word_checkbutton), entire_word);
|
||||
}
|
||||
|
||||
gboolean
|
||||
xed_searchbar_get_entire_word (XedSearchbar *searchbar)
|
||||
{
|
||||
g_return_val_if_fail (XED_IS_SEARCHBAR (searchbar), FALSE);
|
||||
return gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (searchbar->priv->entire_word_checkbutton));
|
||||
}
|
||||
|
||||
void
|
||||
xed_searchbar_set_wrap_around (XedSearchbar *searchbar, gboolean wrap_around)
|
||||
{
|
||||
g_return_if_fail (XED_IS_SEARCHBAR (searchbar));
|
||||
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (searchbar->priv->wrap_around_checkbutton), wrap_around);
|
||||
}
|
||||
|
||||
gboolean
|
||||
xed_searchbar_get_wrap_around (XedSearchbar *searchbar)
|
||||
{
|
||||
g_return_val_if_fail (XED_IS_SEARCHBAR (searchbar), FALSE);
|
||||
return gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (searchbar->priv->wrap_around_checkbutton));
|
||||
}
|
|
@ -0,0 +1,92 @@
|
|||
|
||||
#ifndef __XED_SEARCHBAR_H__
|
||||
#define __XED_SEARCHBAR_H__
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
#include "xed-window.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
/*
|
||||
* Type checking and casting macros
|
||||
*/
|
||||
#define XED_TYPE_SEARCHBAR (xed_searchbar_get_type())
|
||||
#define XED_SEARCHBAR(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), XED_TYPE_SEARCHBAR, XedSearchbar))
|
||||
#define XED_SEARCHBAR_CONST(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), XED_TYPE_SEARCHBAR, XedSearchbar const))
|
||||
#define XED_SEARCHBAR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), XED_TYPE_SEARCHBAR, XedSearchbarClass))
|
||||
#define XED_IS_SEARCHBAR(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), XED_TYPE_SEARCHBAR))
|
||||
#define XED_IS_SEARCHBAR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), XED_TYPE_SEARCHBAR))
|
||||
#define XED_SEARCHBAR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), XED_TYPE_SEARCHBAR, XedSearchbarClass))
|
||||
|
||||
/* Private structure type */
|
||||
typedef struct _XedSearchbarPrivate XedSearchbarPrivate;
|
||||
|
||||
/*
|
||||
* Main object structure
|
||||
*/
|
||||
typedef struct _XedSearchbar XedSearchbar;
|
||||
|
||||
struct _XedSearchbar
|
||||
{
|
||||
GtkBox parent;
|
||||
XedWindow *window;
|
||||
|
||||
/*< private > */
|
||||
XedSearchbarPrivate *priv;
|
||||
};
|
||||
|
||||
/*
|
||||
* Class definition
|
||||
*/
|
||||
typedef struct _XedSearchbarClass XedSearchbarClass;
|
||||
|
||||
struct _XedSearchbarClass
|
||||
{
|
||||
GtkBoxClass parent_class;
|
||||
|
||||
/* Key bindings */
|
||||
gboolean (* show_replace) (XedSearchbar *dlg);
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
XED_SEARCHBAR_FIND_RESPONSE = 100,
|
||||
XED_SEARCHBAR_REPLACE_RESPONSE,
|
||||
XED_SEARCHBAR_REPLACE_ALL_RESPONSE
|
||||
};
|
||||
|
||||
/*
|
||||
* Public methods
|
||||
*/
|
||||
GType xed_searchbar_get_type (void) G_GNUC_CONST;
|
||||
|
||||
GtkWidget *xed_searchbar_new (GtkWindow *parent, gboolean show_replace);
|
||||
|
||||
void xed_searchbar_hide (XedSearchbar *searchbar);
|
||||
void xed_searchbar_show (XedSearchbar *searchbar, gboolean show_replace);
|
||||
void xed_searchbar_find_again (XedSearchbar *searchbar, gboolean backward);
|
||||
|
||||
void xed_searchbar_set_search_text (XedSearchbar *searchbar, const gchar *text);
|
||||
const gchar *xed_searchbar_get_search_text (XedSearchbar *searchbar);
|
||||
|
||||
void xed_searchbar_set_replace_text (XedSearchbar *searchbar, const gchar *text);
|
||||
const gchar *xed_searchbar_get_replace_text (XedSearchbar *searchbar);
|
||||
|
||||
void xed_searchbar_set_match_case (XedSearchbar *searchbar, gboolean match_case);
|
||||
gboolean xed_searchbar_get_match_case (XedSearchbar *searchbar);
|
||||
|
||||
void xed_searchbar_set_entire_word (XedSearchbar *searchbar, gboolean entire_word);
|
||||
gboolean xed_searchbar_get_entire_word (XedSearchbar *searchbar);
|
||||
|
||||
void xed_searchbar_set_backwards (XedSearchbar *searchbar, gboolean backwards);
|
||||
gboolean xed_searchbar_get_backwards (XedSearchbar *searchbar);
|
||||
|
||||
void xed_searchbar_set_wrap_around (XedSearchbar *searchbar, gboolean wrap_around);
|
||||
gboolean xed_searchbar_get_wrap_around (XedSearchbar *searchbar);
|
||||
|
||||
void xed_searchbar_set_parse_escapes (XedSearchbar *searchbar, gboolean parse_escapes);
|
||||
gboolean xed_searchbar_get_parse_escapes (XedSearchbar *searchbar);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __XED_SEARCHBAR_H__ */
|
|
@ -0,0 +1,208 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!-- Generated with glade 3.18.3 -->
|
||||
<!--*- mode: xml -*-->
|
||||
<interface>
|
||||
<requires lib="gtk+" version="3.12"/>
|
||||
<object class="GtkWindow" id="window1">
|
||||
<property name="can_focus">False</property>
|
||||
<property name="hexpand">True</property>
|
||||
<child>
|
||||
<object class="GtkBox" id="searchbar_content">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="orientation">vertical</property>
|
||||
<child>
|
||||
<object class="GtkRevealer" id="revealer">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="transition_type">crossfade</property>
|
||||
<property name="transition_duration">175</property>
|
||||
<property name="reveal_child">True</property>
|
||||
<child>
|
||||
<object class="GtkGrid" id="grid">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="valign">center</property>
|
||||
<property name="border_width">6</property>
|
||||
<property name="column_spacing">3</property>
|
||||
<child>
|
||||
<object class="GtkButton" id="replace_all_button">
|
||||
<property name="label" translatable="yes">Replace All</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">True</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left_attach">4</property>
|
||||
<property name="top_attach">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkButton" id="replace_button">
|
||||
<property name="label" translatable="yes">Replace</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">True</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left_attach">3</property>
|
||||
<property name="top_attach">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel" id="search_label">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="valign">center</property>
|
||||
<property name="hexpand">False</property>
|
||||
<property name="vexpand">False</property>
|
||||
<property name="label" translatable="yes">_Search for: </property>
|
||||
<property name="use_underline">True</property>
|
||||
<property name="xalign">0</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left_attach">1</property>
|
||||
<property name="top_attach">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel" id="replace_with_label">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="label" translatable="yes">Replace _with: </property>
|
||||
<property name="use_underline">True</property>
|
||||
<property name="xalign">0</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left_attach">1</property>
|
||||
<property name="top_attach">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkButton" id="find_button">
|
||||
<property name="label" translatable="yes">Find</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">True</property>
|
||||
<property name="valign">center</property>
|
||||
<property name="hexpand">False</property>
|
||||
<property name="vexpand">False</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left_attach">3</property>
|
||||
<property name="top_attach">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkButton" id="find_prev_button">
|
||||
<property name="label" translatable="yes">Find Prev</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">True</property>
|
||||
<property name="valign">center</property>
|
||||
<property name="hexpand">False</property>
|
||||
<property name="vexpand">False</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left_attach">4</property>
|
||||
<property name="top_attach">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkBox" id="box1">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<child>
|
||||
<object class="GtkToggleButton" id="match_case_checkbutton">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">True</property>
|
||||
<property name="tooltip_text" translatable="yes">Case sensitive</property>
|
||||
<property name="halign">start</property>
|
||||
<child>
|
||||
<object class="GtkImage" id="image1">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="icon_name">xapp-text-case-symbolic</property>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">False</property>
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkToggleButton" id="entire_word_checkbutton">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">True</property>
|
||||
<property name="tooltip_text" translatable="yes">Whole word</property>
|
||||
<property name="halign">start</property>
|
||||
<child>
|
||||
<object class="GtkImage" id="image5">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="icon_name">xapp-search-entire-word-symbolic</property>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">False</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkToggleButton" id="wrap_around_checkbutton">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">True</property>
|
||||
<property name="tooltip_text" translatable="yes">Wrap</property>
|
||||
<property name="active">True</property>
|
||||
<child>
|
||||
<object class="GtkImage" id="image3">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="icon_name">xapp-search-wrap-symbolic</property>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">2</property>
|
||||
</packing>
|
||||
</child>
|
||||
<style>
|
||||
<class name="linked"/>
|
||||
</style>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left_attach">0</property>
|
||||
<property name="top_attach">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<placeholder/>
|
||||
</child>
|
||||
<child>
|
||||
<placeholder/>
|
||||
</child>
|
||||
<child>
|
||||
<placeholder/>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</interface>
|
|
@ -116,12 +116,8 @@ static const GtkActionEntry xed_menu_entries[] =
|
|||
N_("Search backwards for the same text"), G_CALLBACK (_xed_cmd_search_find_prev) },
|
||||
{ "SearchReplace", GTK_STOCK_FIND_AND_REPLACE, N_("_Replace..."), "<control>H",
|
||||
N_("Search for and replace text"), G_CALLBACK (_xed_cmd_search_replace) },
|
||||
{ "SearchClearHighlight", NULL, N_("_Clear Highlight"), "<shift><control>K",
|
||||
N_("Clear highlighting of search matches"), G_CALLBACK (_xed_cmd_search_clear_highlight) },
|
||||
{ "SearchGoToLine", GTK_STOCK_JUMP_TO, N_("Go to _Line..."), "<control>I",
|
||||
N_("Go to a specific line"), G_CALLBACK (_xed_cmd_search_goto_line) },
|
||||
{ "SearchIncrementalSearch", GTK_STOCK_FIND, N_("_Incremental Search..."), "<control>K",
|
||||
N_("Incrementally search for text"), G_CALLBACK (_xed_cmd_search_incremental_search) },
|
||||
|
||||
/* Documents menu */
|
||||
{ "FileSaveAll", GTK_STOCK_SAVE, N_("_Save All"), "<shift><control>L",
|
||||
|
|
|
@ -1,31 +1,3 @@
|
|||
<!--
|
||||
* xed-ui.xml
|
||||
* This file is part of xed
|
||||
*
|
||||
* Copyright (C) 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 of the License, 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., 51 Franklin Street, Fifth Floor,
|
||||
* Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Modified by the xed Team, 2005. See the AUTHORS file for a
|
||||
* list of people on the xed Team.
|
||||
* See the ChangeLog files for a list of changes.
|
||||
*
|
||||
* $Id$
|
||||
-->
|
||||
|
||||
<ui>
|
||||
|
||||
<menubar name="MenuBar">
|
||||
|
@ -93,7 +65,6 @@
|
|||
<menuitem name="SearchFindMenu" action="SearchFind"/>
|
||||
<menuitem name="SearchFindNextMenu" action="SearchFindNext"/>
|
||||
<menuitem name="SearchFindPreviousMenu" action="SearchFindPrevious"/>
|
||||
<menuitem name="SearchIncrementalSearchMenu" action="SearchIncrementalSearch"/>
|
||||
<placeholder name="SearchOps_1" />
|
||||
<separator/>
|
||||
<placeholder name="SearchOps_2" />
|
||||
|
@ -103,7 +74,6 @@
|
|||
<separator/>
|
||||
<placeholder name="SearchOps_4" />
|
||||
<separator/>
|
||||
<menuitem name="SearchClearHighlight" action="SearchClearHighlight"/>
|
||||
<placeholder name="SearchOps_5" />
|
||||
<separator/>
|
||||
<placeholder name="SearchOps_6" />
|
||||
|
|
2417
xed/xed-view.c
2417
xed/xed-view.c
File diff suppressed because it is too large
Load Diff
|
@ -1,33 +1,3 @@
|
|||
/*
|
||||
* xed-view.h
|
||||
* This file is part of xed
|
||||
*
|
||||
* Copyright (C) 1998, 1999 Alex Roberts, Evan Lawrence
|
||||
* Copyright (C) 2000, 2001 Chema Celorio, Paolo Maggi
|
||||
* 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 of the License, 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., 51 Franklin St, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Modified by the xed Team, 1998-2005. See the AUTHORS file for a
|
||||
* list of people on the xed Team.
|
||||
* See the ChangeLog files for a list of changes.
|
||||
*/
|
||||
|
||||
#ifndef __XED_VIEW_H__
|
||||
#define __XED_VIEW_H__
|
||||
|
||||
|
@ -41,67 +11,59 @@ G_BEGIN_DECLS
|
|||
/*
|
||||
* Type checking and casting macros
|
||||
*/
|
||||
#define XED_TYPE_VIEW (xed_view_get_type ())
|
||||
#define XED_VIEW(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), XED_TYPE_VIEW, XedView))
|
||||
#define XED_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), XED_TYPE_VIEW, XedViewClass))
|
||||
#define XED_IS_VIEW(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), XED_TYPE_VIEW))
|
||||
#define XED_TYPE_VIEW (xed_view_get_type ())
|
||||
#define XED_VIEW(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), XED_TYPE_VIEW, XedView))
|
||||
#define XED_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), XED_TYPE_VIEW, XedViewClass))
|
||||
#define XED_IS_VIEW(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), XED_TYPE_VIEW))
|
||||
#define XED_IS_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), XED_TYPE_VIEW))
|
||||
#define XED_VIEW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), XED_TYPE_VIEW, XedViewClass))
|
||||
#define XED_VIEW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), XED_TYPE_VIEW, XedViewClass))
|
||||
|
||||
/* Private structure type */
|
||||
typedef struct _XedViewPrivate XedViewPrivate;
|
||||
typedef struct _XedViewPrivate XedViewPrivate;
|
||||
|
||||
/*
|
||||
* Main object structure
|
||||
*/
|
||||
typedef struct _XedView XedView;
|
||||
typedef struct _XedView XedView;
|
||||
|
||||
struct _XedView
|
||||
{
|
||||
GtkSourceView view;
|
||||
GtkSourceView view;
|
||||
|
||||
/*< private > */
|
||||
XedViewPrivate *priv;
|
||||
/*< private > */
|
||||
XedViewPrivate *priv;
|
||||
};
|
||||
|
||||
/*
|
||||
* Class definition
|
||||
*/
|
||||
typedef struct _XedViewClass XedViewClass;
|
||||
typedef struct _XedViewClass XedViewClass;
|
||||
|
||||
struct _XedViewClass
|
||||
{
|
||||
GtkSourceViewClass parent_class;
|
||||
GtkSourceViewClass parent_class;
|
||||
|
||||
/* FIXME: Do we need placeholders ? */
|
||||
/* FIXME: Do we need placeholders ? */
|
||||
|
||||
/* Key bindings */
|
||||
gboolean (* start_interactive_search) (XedView *view);
|
||||
gboolean (* start_interactive_goto_line)(XedView *view);
|
||||
gboolean (* reset_searched_text) (XedView *view);
|
||||
|
||||
void (* drop_uris) (XedView *view,
|
||||
gchar **uri_list);
|
||||
/* Key bindings */
|
||||
gboolean (* start_interactive_search) (XedView *view);
|
||||
gboolean (* start_interactive_goto_line)(XedView *view);
|
||||
gboolean (* reset_searched_text) (XedView *view);
|
||||
void (* drop_uris) (XedView *view, gchar **uri_list);
|
||||
};
|
||||
|
||||
/*
|
||||
* Public methods
|
||||
*/
|
||||
GType xed_view_get_type (void) G_GNUC_CONST;
|
||||
|
||||
GtkWidget *xed_view_new (XedDocument *doc);
|
||||
|
||||
void xed_view_cut_clipboard (XedView *view);
|
||||
void xed_view_copy_clipboard (XedView *view);
|
||||
void xed_view_paste_clipboard (XedView *view);
|
||||
void xed_view_delete_selection (XedView *view);
|
||||
void xed_view_select_all (XedView *view);
|
||||
|
||||
void xed_view_scroll_to_cursor (XedView *view);
|
||||
|
||||
void xed_view_set_font (XedView *view,
|
||||
gboolean def,
|
||||
const gchar *font_name);
|
||||
GType xed_view_get_type (void) G_GNUC_CONST;
|
||||
GtkWidget *xed_view_new (XedDocument *doc);
|
||||
void xed_view_cut_clipboard (XedView *view);
|
||||
void xed_view_copy_clipboard (XedView *view);
|
||||
void xed_view_paste_clipboard (XedView *view);
|
||||
void xed_view_delete_selection (XedView *view);
|
||||
void xed_view_select_all (XedView *view);
|
||||
void xed_view_scroll_to_cursor (XedView *view);
|
||||
void xed_view_set_font (XedView *view, gboolean def, const gchar *font_name);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
|
|
|
@ -61,6 +61,7 @@ struct _XedWindowPrivate
|
|||
|
||||
/* statusbar and context ids for statusbar messages */
|
||||
GtkWidget *statusbar;
|
||||
GtkWidget *searchbar;
|
||||
guint generic_message_cid;
|
||||
guint tip_message_cid;
|
||||
guint tab_width_id;
|
||||
|
|
5472
xed/xed-window.c
5472
xed/xed-window.c
File diff suppressed because it is too large
Load Diff
189
xed/xed-window.h
189
xed/xed-window.h
|
@ -1,33 +1,3 @@
|
|||
/*
|
||||
* xed-window.h
|
||||
* This file is part of xed
|
||||
*
|
||||
* Copyright (C) 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 of the License, 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
|
||||
* MERCHANWINDOWILITY 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., 51 Franklin St, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Modified by the xed Team, 2005. See the AUTHORS file for a
|
||||
* list of people on the xed Team.
|
||||
* See the ChangeLog files for a list of changes.
|
||||
*
|
||||
* $Id$
|
||||
*/
|
||||
|
||||
#ifndef __XED_WINDOW_H__
|
||||
#define __XED_WINDOW_H__
|
||||
|
||||
|
@ -42,23 +12,23 @@ G_BEGIN_DECLS
|
|||
|
||||
typedef enum
|
||||
{
|
||||
XED_WINDOW_STATE_NORMAL = 0,
|
||||
XED_WINDOW_STATE_SAVING = 1 << 1,
|
||||
XED_WINDOW_STATE_PRINTING = 1 << 2,
|
||||
XED_WINDOW_STATE_LOADING = 1 << 3,
|
||||
XED_WINDOW_STATE_ERROR = 1 << 4,
|
||||
XED_WINDOW_STATE_SAVING_SESSION = 1 << 5
|
||||
XED_WINDOW_STATE_NORMAL = 0,
|
||||
XED_WINDOW_STATE_SAVING = 1 << 1,
|
||||
XED_WINDOW_STATE_PRINTING = 1 << 2,
|
||||
XED_WINDOW_STATE_LOADING = 1 << 3,
|
||||
XED_WINDOW_STATE_ERROR = 1 << 4,
|
||||
XED_WINDOW_STATE_SAVING_SESSION = 1 << 5
|
||||
} XedWindowState;
|
||||
|
||||
/*
|
||||
* Type checking and casting macros
|
||||
*/
|
||||
#define XED_TYPE_WINDOW (xed_window_get_type())
|
||||
#define XED_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), XED_TYPE_WINDOW, XedWindow))
|
||||
#define XED_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), XED_TYPE_WINDOW, XedWindowClass))
|
||||
#define XED_IS_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), XED_TYPE_WINDOW))
|
||||
#define XED_IS_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), XED_TYPE_WINDOW))
|
||||
#define XED_WINDOW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), XED_TYPE_WINDOW, XedWindowClass))
|
||||
#define XED_TYPE_WINDOW (xed_window_get_type())
|
||||
#define XED_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), XED_TYPE_WINDOW, XedWindow))
|
||||
#define XED_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), XED_TYPE_WINDOW, XedWindowClass))
|
||||
#define XED_IS_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), XED_TYPE_WINDOW))
|
||||
#define XED_IS_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), XED_TYPE_WINDOW))
|
||||
#define XED_WINDOW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), XED_TYPE_WINDOW, XedWindowClass))
|
||||
|
||||
/* Private structure type */
|
||||
typedef struct _XedWindowPrivate XedWindowPrivate;
|
||||
|
@ -70,10 +40,10 @@ typedef struct _XedWindow XedWindow;
|
|||
|
||||
struct _XedWindow
|
||||
{
|
||||
GtkWindow window;
|
||||
GtkWindow window;
|
||||
|
||||
/*< private > */
|
||||
XedWindowPrivate *priv;
|
||||
/*< private > */
|
||||
XedWindowPrivate *priv;
|
||||
};
|
||||
|
||||
/*
|
||||
|
@ -83,113 +53,72 @@ typedef struct _XedWindowClass XedWindowClass;
|
|||
|
||||
struct _XedWindowClass
|
||||
{
|
||||
GtkWindowClass parent_class;
|
||||
GtkWindowClass parent_class;
|
||||
|
||||
/* Signals */
|
||||
void (* tab_added) (XedWindow *window,
|
||||
XedTab *tab);
|
||||
void (* tab_removed) (XedWindow *window,
|
||||
XedTab *tab);
|
||||
void (* tabs_reordered) (XedWindow *window);
|
||||
void (* active_tab_changed) (XedWindow *window,
|
||||
XedTab *tab);
|
||||
void (* active_tab_state_changed)
|
||||
(XedWindow *window);
|
||||
/* Signals */
|
||||
void (* tab_added) (XedWindow *window, XedTab *tab);
|
||||
void (* tab_removed) (XedWindow *window, XedTab *tab);
|
||||
void (* tabs_reordered) (XedWindow *window);
|
||||
void (* active_tab_changed) (XedWindow *window, XedTab *tab);
|
||||
void (* active_tab_state_changed) (XedWindow *window);
|
||||
};
|
||||
|
||||
/*
|
||||
* Public methods
|
||||
*/
|
||||
GType xed_window_get_type (void) G_GNUC_CONST;
|
||||
|
||||
XedTab *xed_window_create_tab (XedWindow *window,
|
||||
gboolean jump_to);
|
||||
|
||||
XedTab *xed_window_create_tab_from_uri (XedWindow *window,
|
||||
const gchar *uri,
|
||||
const XedEncoding *encoding,
|
||||
gint line_pos,
|
||||
gboolean create,
|
||||
gboolean jump_to);
|
||||
|
||||
void xed_window_close_tab (XedWindow *window,
|
||||
XedTab *tab);
|
||||
|
||||
void xed_window_close_all_tabs (XedWindow *window);
|
||||
|
||||
void xed_window_close_tabs (XedWindow *window,
|
||||
const GList *tabs);
|
||||
|
||||
XedTab *xed_window_get_active_tab (XedWindow *window);
|
||||
|
||||
void xed_window_set_active_tab (XedWindow *window,
|
||||
XedTab *tab);
|
||||
GType xed_window_get_type (void) G_GNUC_CONST;
|
||||
XedTab *xed_window_create_tab (XedWindow *window, gboolean jump_to);
|
||||
XedTab *xed_window_create_tab_from_uri (XedWindow *window, const gchar *uri, const XedEncoding *encoding,
|
||||
gint line_pos, gboolean create, gboolean jump_to);
|
||||
void xed_window_close_tab (XedWindow *window, XedTab *tab);
|
||||
void xed_window_close_all_tabs (XedWindow *window);
|
||||
void xed_window_close_tabs (XedWindow *window, const GList *tabs);
|
||||
XedTab *xed_window_get_active_tab (XedWindow *window);
|
||||
void xed_window_set_active_tab (XedWindow *window, XedTab *tab);
|
||||
|
||||
/* Helper functions */
|
||||
XedView *xed_window_get_active_view (XedWindow *window);
|
||||
XedDocument *xed_window_get_active_document (XedWindow *window);
|
||||
XedView *xed_window_get_active_view (XedWindow *window);
|
||||
XedDocument *xed_window_get_active_document (XedWindow *window);
|
||||
|
||||
/* Returns a newly allocated list with all the documents in the window */
|
||||
GList *xed_window_get_documents (XedWindow *window);
|
||||
GList *xed_window_get_documents (XedWindow *window);
|
||||
|
||||
/* Returns a newly allocated list with all the documents that need to be
|
||||
saved before closing the window */
|
||||
GList *xed_window_get_unsaved_documents (XedWindow *window);
|
||||
saved before closing the window */
|
||||
GList *xed_window_get_unsaved_documents (XedWindow *window);
|
||||
|
||||
/* Returns a newly allocated list with all the views in the window */
|
||||
GList *xed_window_get_views (XedWindow *window);
|
||||
|
||||
GtkWindowGroup *xed_window_get_group (XedWindow *window);
|
||||
|
||||
XedPanel *xed_window_get_side_panel (XedWindow *window);
|
||||
|
||||
XedPanel *xed_window_get_bottom_panel (XedWindow *window);
|
||||
|
||||
GtkWidget *xed_window_get_statusbar (XedWindow *window);
|
||||
|
||||
GtkUIManager *xed_window_get_ui_manager (XedWindow *window);
|
||||
|
||||
XedWindowState xed_window_get_state (XedWindow *window);
|
||||
|
||||
XedTab *xed_window_get_tab_from_location (XedWindow *window,
|
||||
GFile *location);
|
||||
|
||||
XedTab *xed_window_get_tab_from_uri (XedWindow *window,
|
||||
const gchar *uri);
|
||||
GList *xed_window_get_views (XedWindow *window);
|
||||
GtkWindowGroup *xed_window_get_group (XedWindow *window);
|
||||
XedPanel *xed_window_get_side_panel (XedWindow *window);
|
||||
XedPanel *xed_window_get_bottom_panel (XedWindow *window);
|
||||
GtkWidget *xed_window_get_statusbar (XedWindow *window);
|
||||
GtkWidget *xed_window_get_searchbar (XedWindow *window);
|
||||
GtkUIManager *xed_window_get_ui_manager (XedWindow *window);
|
||||
XedWindowState xed_window_get_state (XedWindow *window);
|
||||
XedTab *xed_window_get_tab_from_location (XedWindow *window, GFile *location);
|
||||
XedTab *xed_window_get_tab_from_uri (XedWindow *window, const gchar *uri);
|
||||
|
||||
/* Message bus */
|
||||
XedMessageBus *xed_window_get_message_bus (XedWindow *window);
|
||||
XedMessageBus *xed_window_get_message_bus (XedWindow *window);
|
||||
|
||||
/*
|
||||
* Non exported functions
|
||||
*/
|
||||
GtkWidget *_xed_window_get_notebook (XedWindow *window);
|
||||
|
||||
XedWindow *_xed_window_move_tab_to_new_window (XedWindow *window,
|
||||
XedTab *tab);
|
||||
gboolean _xed_window_is_removing_tabs (XedWindow *window);
|
||||
|
||||
GFile *_xed_window_get_default_location (XedWindow *window);
|
||||
|
||||
void _xed_window_set_default_location (XedWindow *window,
|
||||
GFile *location);
|
||||
|
||||
void _xed_window_set_saving_session_state (XedWindow *window,
|
||||
gboolean saving_session);
|
||||
|
||||
void _xed_window_fullscreen (XedWindow *window);
|
||||
|
||||
void _xed_window_unfullscreen (XedWindow *window);
|
||||
|
||||
gboolean _xed_window_is_fullscreen (XedWindow *window);
|
||||
GtkWidget *_xed_window_get_notebook (XedWindow *window);
|
||||
XedWindow *_xed_window_move_tab_to_new_window (XedWindow *window, XedTab *tab);
|
||||
gboolean _xed_window_is_removing_tabs (XedWindow *window);
|
||||
GFile *_xed_window_get_default_location (XedWindow *window);
|
||||
void _xed_window_set_default_location (XedWindow *window, GFile *location);
|
||||
void _xed_window_set_saving_session_state (XedWindow *window, gboolean saving_session);
|
||||
void _xed_window_fullscreen (XedWindow *window);
|
||||
void _xed_window_unfullscreen (XedWindow *window);
|
||||
gboolean _xed_window_is_fullscreen (XedWindow *window);
|
||||
|
||||
/* these are in xed-window because of screen safety */
|
||||
void _xed_recent_add (XedWindow *window,
|
||||
const gchar *uri,
|
||||
const gchar *mime);
|
||||
void _xed_recent_remove (XedWindow *window,
|
||||
const gchar *uri);
|
||||
void _xed_recent_add (XedWindow *window, const gchar *uri, const gchar *mime);
|
||||
void _xed_recent_remove (XedWindow *window, const gchar *uri);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __XED_WINDOW_H__ */
|
||||
#endif /* __XED_WINDOW_H__ */
|
||||
|
|
Loading…
Reference in New Issue