ClipIt-v1.1.0-09112010001-beta
+ Added: Option to show index numbers in history. + Fixed: Search window now gets properly focused when launched with the hotkey. + Fixed: Search window is now resizable. + Fixed: Double casting when calling 'item_selected'. + Fixed: Removed some unnecessary comments and fixed some of the others. + Fixed: Moved search dialog and functions to manage.c, as this dialog will become "Manage Clipboard" in the next version. Changes to be committed: modified: ChangeLog modified: TODO modified: configure.in modified: src/Makefile.am modified: src/main.c modified: src/main.h new file: src/manage.c new file: src/manage.h modified: src/preferences.c modified: src/preferences.h
This commit is contained in:
parent
866aa76e3d
commit
3ed97a051e
@ -1,3 +1,12 @@
|
||||
ClipIt-v1.1.0-09112010001 - 09 Nov. 2010
|
||||
+ Added: Option to show index numbers in history.
|
||||
+ Fixed: Search window now gets properly focused when launched with the hotkey.
|
||||
+ Fixed: Search window is now resizable.
|
||||
+ Fixed: Double casting when calling 'item_selected'.
|
||||
+ Fixed: Removed some unnecessary comments and fixed some of the others.
|
||||
+ Fixed: Moved search dialog and functions to manage.c, as this dialog will
|
||||
become "Manage Clipboard" in the next version.
|
||||
|
||||
ClipIt-v1.0.0-05112010001 - 05 Nov. 2010
|
||||
Changes from Parcellite 0.9.2:
|
||||
+ Created "Small history" for quick access to last used items.
|
||||
|
4
TODO
4
TODO
@ -6,4 +6,6 @@
|
||||
+ Redo Preferences dialog.
|
||||
+ Clean up the code and indent it properly.
|
||||
+ Fix conflict with copying of multimedia content.
|
||||
+ Make Search dialog receive focus as soon as it is opened.
|
||||
+ Add "Edit" and "Remove" buttons to the search window and rename
|
||||
it to "Manage Clipboard".
|
||||
+ Move all pop-up and menu functions from main.c to menus.c.
|
||||
|
@ -2,7 +2,7 @@
|
||||
# Autoconf/automake.
|
||||
# -------------------------------------------------------------------------------
|
||||
AC_PREREQ([2.5])
|
||||
AC_INIT([clipit], [1.0.0], [oss@web-tm.com])
|
||||
AC_INIT([clipit], [1.1.0], [oss@web-tm.com])
|
||||
AM_INIT_AUTOMAKE([AC_PACKAGE_TARNAME()], [AC_PACKAGE_VERSION()])
|
||||
|
||||
AC_CONFIG_MACRO_DIR([m4])
|
||||
|
@ -13,4 +13,5 @@ clipit_SOURCES = main.c main.h \
|
||||
history.c history.h \
|
||||
keybinder.c keybinder.h \
|
||||
preferences.c preferences.h \
|
||||
manage.c manage.h \
|
||||
eggaccelerators.c eggaccelerators.h
|
||||
|
219
src/main.c
219
src/main.c
@ -33,6 +33,7 @@
|
||||
#include "history.h"
|
||||
#include "keybinder.h"
|
||||
#include "preferences.h"
|
||||
#include "manage.h"
|
||||
#include "clipit-i18n.h"
|
||||
|
||||
|
||||
@ -47,7 +48,7 @@ static gboolean actions_lock = FALSE;
|
||||
|
||||
/* Init preferences structure */
|
||||
prefs_t prefs = {DEF_USE_COPY, DEF_USE_PRIMARY, DEF_SYNCHRONIZE,
|
||||
DEF_SAVE_HISTORY, DEF_HISTORY_LIMIT,
|
||||
DEF_SHOW_INDEXES, DEF_SAVE_HISTORY, DEF_HISTORY_LIMIT,
|
||||
DEF_SMALL_HISTORY, DEF_HISTORY_SMALL,
|
||||
DEF_HYPERLINKS_ONLY, DEF_CONFIRM_CLEAR, DEF_FULL_HIST_BUTTON,
|
||||
DEF_SINGLE_LINE, DEF_REVERSE_HISTORY, DEF_ITEM_LENGTH,
|
||||
@ -55,11 +56,6 @@ prefs_t prefs = {DEF_USE_COPY, DEF_USE_PRIMARY, DEF_SYNCHRONIZE,
|
||||
INIT_HISTORY_KEY, INIT_ACTIONS_KEY, INIT_MENU_KEY,
|
||||
INIT_SEARCH_KEY, DEF_NO_ICON};
|
||||
|
||||
GtkListStore* search_list;
|
||||
GtkWidget *search_entry;
|
||||
GtkTreeSelection* search_selection;
|
||||
GtkWidget* search_dialog;
|
||||
|
||||
/* Called every CHECK_INTERVAL seconds to check for new items */
|
||||
static gboolean
|
||||
item_check(gpointer data)
|
||||
@ -130,9 +126,9 @@ item_check(gpointer data)
|
||||
GdkAtom *targets;
|
||||
gboolean contents = gtk_clipboard_wait_for_targets(primary, &targets, &count);
|
||||
g_free(targets);
|
||||
/* Only recover lost contents if there isn't any other type of content in the clipboard */
|
||||
if (!contents)
|
||||
{
|
||||
/* Only recover lost contents if there isn't any other type of content in the clipboard */
|
||||
if (!contents)
|
||||
{
|
||||
g_print("Clipboard is null, recovering ...\n");
|
||||
gtk_clipboard_set_text(clipboard, clipboard_text, -1);
|
||||
}
|
||||
@ -445,154 +441,6 @@ show_about_dialog(GtkMenuItem *menu_item, gpointer user_data)
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
search_doubleclick()
|
||||
{
|
||||
GtkTreeIter sel_iter;
|
||||
/* Check if selected */
|
||||
if (gtk_tree_selection_get_selected(search_selection, NULL, &sel_iter))
|
||||
{
|
||||
gchar *selected_item;
|
||||
gtk_tree_model_get((GtkTreeModel*)search_list, &sel_iter, 0, &selected_item, -1);
|
||||
GString* s_selected_item = g_string_new(selected_item);
|
||||
GtkClipboard* clip = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD);
|
||||
gtk_clipboard_set_text(clip, (gchar*)selected_item, -1);
|
||||
gtk_widget_destroy(search_dialog);
|
||||
g_free(selected_item);
|
||||
g_string_free(s_selected_item, TRUE);
|
||||
}
|
||||
}
|
||||
|
||||
gint
|
||||
search_click(GtkWidget *widget, GdkEventButton *event, gpointer func_data)
|
||||
{
|
||||
if(event->type==GDK_2BUTTON_PRESS || event->type==GDK_3BUTTON_PRESS)
|
||||
{
|
||||
search_doubleclick();
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* Search through the history */
|
||||
void
|
||||
search_history()
|
||||
{
|
||||
guint16 search_len = gtk_entry_get_text_length((GtkEntry*)search_entry);
|
||||
gchar* search_input = g_strdup(gtk_entry_get_text((GtkEntry*)search_entry));
|
||||
gchar* search_reg = g_regex_escape_string(search_input, search_len);
|
||||
gchar* search_regex = g_strconcat (".*", search_reg, ".*", NULL);
|
||||
GRegex* regex = g_regex_new(search_regex, G_REGEX_CASELESS, 0, NULL);
|
||||
GtkTreeIter search_iter;
|
||||
while(gtk_tree_model_get_iter_first((GtkTreeModel*)search_list, &search_iter))
|
||||
gtk_list_store_remove(search_list, &search_iter);
|
||||
// Test if there is text in the search box
|
||||
if(search_len > 0)
|
||||
{
|
||||
if ((history != NULL) && (history->data != NULL))
|
||||
{
|
||||
// Declare some variables
|
||||
GSList* element;
|
||||
gint element_number = 0;
|
||||
// Go through each element and adding each
|
||||
for (element = history; element != NULL; element = element->next)
|
||||
{
|
||||
GString* string = g_string_new((gchar*)element->data);
|
||||
gchar* compare = string->str;
|
||||
gboolean result = g_regex_match(regex, compare, 0, NULL);
|
||||
//g_free(compare);
|
||||
if(result)
|
||||
{
|
||||
GtkTreeIter row_iter;
|
||||
gtk_list_store_append(search_list, &row_iter);
|
||||
gtk_list_store_set(search_list, &row_iter, 0, string->str, -1);
|
||||
}
|
||||
// Prepare for next item
|
||||
g_string_free(string, TRUE);
|
||||
element_number++;
|
||||
}
|
||||
}
|
||||
g_regex_unref(regex);
|
||||
}
|
||||
g_free(search_regex);
|
||||
}
|
||||
|
||||
gint
|
||||
search_key_pressed(GtkWidget *widget, GdkEventKey *event, gpointer user_data)
|
||||
{
|
||||
/* Check if [Return] key was pressed */
|
||||
if ((event->keyval == 0xff0d) || (event->keyval == 0xff8d))
|
||||
search_history();
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* Shows the search dialog */
|
||||
void
|
||||
show_search()
|
||||
{
|
||||
/* Declare some variables */
|
||||
GtkWidget *frame, *label,
|
||||
*alignment, *hbox,
|
||||
*vbox;
|
||||
|
||||
GtkTreeViewColumn *tree_column;
|
||||
|
||||
/* Create the dialog */
|
||||
search_dialog = gtk_dialog_new_with_buttons(_("Search"), NULL,
|
||||
(GTK_DIALOG_MODAL + GTK_DIALOG_NO_SEPARATOR),
|
||||
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, NULL);
|
||||
|
||||
gtk_window_set_icon((GtkWindow*)search_dialog, gtk_widget_render_icon(search_dialog, GTK_STOCK_FIND, GTK_ICON_SIZE_MENU, NULL));
|
||||
gtk_window_set_resizable((GtkWindow*)search_dialog, FALSE);
|
||||
|
||||
GtkWidget* vbox_search = gtk_vbox_new(FALSE, 12);
|
||||
gtk_box_pack_start(GTK_BOX(gtk_dialog_get_content_area (GTK_DIALOG(search_dialog))), vbox_search, TRUE, TRUE, 2);
|
||||
gtk_widget_set_size_request((GtkWidget*)vbox_search, 400, 600);
|
||||
gtk_window_set_position((GtkWindow*)search_dialog, GTK_WIN_POS_CENTER);
|
||||
|
||||
hbox = gtk_hbox_new(TRUE, 4);
|
||||
gtk_box_pack_start((GtkBox*)vbox_search, hbox, FALSE, FALSE, 0);
|
||||
search_entry = gtk_entry_new();
|
||||
gtk_box_pack_end((GtkBox*)hbox, search_entry, TRUE, TRUE, 0);
|
||||
GtkWidget* add_button_exclude = gtk_button_new_with_label(_("Search"));
|
||||
g_signal_connect((GObject*)search_entry, "key-press-event", (GCallback)search_key_pressed, NULL);
|
||||
//label = gtk_label_new(_("Search for:"));
|
||||
//gtk_label_set_line_wrap((GtkLabel*)label, TRUE);
|
||||
//gtk_misc_set_alignment((GtkMisc*)label, 0.0, 0.50);
|
||||
//gtk_label_set_max_width_chars((GtkMisc*)label, 12);
|
||||
//gtk_box_pack_start((GtkBox*)hbox, label, FALSE, FALSE, 0);
|
||||
|
||||
/* Build the exclude treeview */
|
||||
GtkWidget* scrolled_window_search = gtk_scrolled_window_new(
|
||||
(GtkAdjustment*)gtk_adjustment_new(0, 0, 0, 0, 0, 0),
|
||||
(GtkAdjustment*)gtk_adjustment_new(0, 0, 0, 0, 0, 0));
|
||||
|
||||
gtk_scrolled_window_set_policy((GtkScrolledWindow*)scrolled_window_search, GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
|
||||
gtk_scrolled_window_set_shadow_type((GtkScrolledWindow*)scrolled_window_search, GTK_SHADOW_ETCHED_OUT);
|
||||
GtkWidget* treeview_search = gtk_tree_view_new();
|
||||
gtk_tree_view_set_reorderable((GtkTreeView*)treeview_search, TRUE);
|
||||
gtk_tree_view_set_rules_hint((GtkTreeView*)treeview_search, TRUE);
|
||||
search_list = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_STRING);
|
||||
gtk_tree_view_set_model((GtkTreeView*)treeview_search, (GtkTreeModel*)search_list);
|
||||
GtkCellRenderer* name_renderer_exclude = gtk_cell_renderer_text_new();
|
||||
g_object_set(name_renderer_exclude, "ellipsize", PANGO_ELLIPSIZE_END, NULL);
|
||||
g_object_set(name_renderer_exclude, "single-paragraph-mode", TRUE, NULL);
|
||||
tree_column = gtk_tree_view_column_new_with_attributes(_("Results"), name_renderer_exclude, "text", 0, NULL);
|
||||
gtk_tree_view_column_set_resizable(tree_column, TRUE);
|
||||
gtk_tree_view_append_column((GtkTreeView*)treeview_search, tree_column);
|
||||
gtk_container_add((GtkContainer*)scrolled_window_search, treeview_search);
|
||||
gtk_box_pack_start((GtkBox*)vbox_search, scrolled_window_search, TRUE, TRUE, 0);
|
||||
|
||||
search_selection = gtk_tree_view_get_selection((GtkTreeView*)treeview_search);
|
||||
gtk_tree_selection_set_mode(search_selection, GTK_SELECTION_BROWSE);
|
||||
g_signal_connect((GObject*)treeview_search, "button_press_event", (GCallback)search_click, NULL);
|
||||
|
||||
gtk_widget_show_all(search_dialog);
|
||||
|
||||
/* Run the dialog */
|
||||
gtk_dialog_run((GtkDialog*)search_dialog);
|
||||
gtk_widget_destroy(search_dialog);
|
||||
}
|
||||
|
||||
/* Called when Preferences is selected from right-click menu */
|
||||
static void
|
||||
preferences_selected(GtkMenuItem *menu_item, gpointer user_data)
|
||||
@ -747,7 +595,7 @@ show_history_menu_full(gpointer data)
|
||||
{
|
||||
/* Declare some variables */
|
||||
GSList* element;
|
||||
gint element_number = 0;
|
||||
gint64 element_number = 0;
|
||||
gchar* primary_temp = gtk_clipboard_wait_for_text(primary);
|
||||
gchar* clipboard_temp = gtk_clipboard_wait_for_text(clipboard);
|
||||
/* Reverse history if enabled */
|
||||
@ -789,10 +637,16 @@ show_history_menu_full(gpointer data)
|
||||
}
|
||||
}
|
||||
/* Make new item with ellipsized text */
|
||||
menu_item = gtk_menu_item_new_with_label(string->str);
|
||||
gchar* list_item;
|
||||
if (prefs.show_indexes)
|
||||
{
|
||||
list_item = g_strdup_printf("%" G_GINT64_FORMAT ". %s", (element_number+1), string->str);
|
||||
} else {
|
||||
list_item = g_strdup(string->str);
|
||||
}
|
||||
menu_item = gtk_menu_item_new_with_label(list_item);
|
||||
g_signal_connect((GObject*)menu_item, "activate",
|
||||
(GCallback)item_selected, (gpointer)(gint64)element_number);
|
||||
|
||||
(GCallback)item_selected, (gpointer)element_number);
|
||||
/* Modify menu item label properties */
|
||||
item_label = gtk_bin_get_child((GtkBin*)menu_item);
|
||||
gtk_label_set_single_line_mode((GtkLabel*)item_label, prefs.single_line);
|
||||
@ -800,16 +654,17 @@ show_history_menu_full(gpointer data)
|
||||
/* Check if item is also clipboard text and make bold */
|
||||
if ((clipboard_temp) && (g_strcmp0((gchar*)element->data, clipboard_temp) == 0))
|
||||
{
|
||||
gchar* bold_text = g_markup_printf_escaped("<b>%s</b>", string->str);
|
||||
gchar* bold_text = g_markup_printf_escaped("<b>%s</b>", list_item);
|
||||
gtk_label_set_markup((GtkLabel*)item_label, bold_text);
|
||||
g_free(bold_text);
|
||||
}
|
||||
else if ((primary_temp) && (g_strcmp0((gchar*)element->data, primary_temp) == 0))
|
||||
{
|
||||
gchar* italic_text = g_markup_printf_escaped("<i>%s</i>", string->str);
|
||||
gchar* italic_text = g_markup_printf_escaped("<i>%s</i>", list_item);
|
||||
gtk_label_set_markup((GtkLabel*)item_label, italic_text);
|
||||
g_free(italic_text);
|
||||
}
|
||||
g_free(list_item);
|
||||
/* Append item */
|
||||
gtk_menu_shell_append((GtkMenuShell*)menu, menu_item);
|
||||
/* Prepare for next item */
|
||||
@ -857,21 +712,13 @@ show_history_menu_small(gpointer data)
|
||||
/* Create the menu */
|
||||
menu = gtk_menu_new();
|
||||
g_signal_connect((GObject*)menu, "selection-done", (GCallback)gtk_widget_destroy, NULL);
|
||||
/* Edit clipboard
|
||||
menu_item = gtk_image_menu_item_new_with_mnemonic(_("_Edit Clipboard"));
|
||||
menu_image = gtk_image_new_from_stock(GTK_STOCK_EDIT, GTK_ICON_SIZE_MENU);
|
||||
gtk_image_menu_item_set_image((GtkImageMenuItem*)menu_item, menu_image);
|
||||
g_signal_connect((GObject*)menu_item, "activate", (GCallback)edit_selected, NULL);
|
||||
gtk_menu_shell_append((GtkMenuShell*)menu, menu_item);
|
||||
-------------------- */
|
||||
// gtk_menu_shell_append((GtkMenuShell*)menu, gtk_separator_menu_item_new());
|
||||
/* Items */
|
||||
if ((history != NULL) && (history->data != NULL))
|
||||
{
|
||||
/* Declare some variables */
|
||||
GSList* element;
|
||||
gint element_number = 0;
|
||||
gint element_number_small = 0;
|
||||
gint64 element_number = 0;
|
||||
gint64 element_number_small = 0;
|
||||
gchar* primary_temp = gtk_clipboard_wait_for_text(primary);
|
||||
gchar* clipboard_temp = gtk_clipboard_wait_for_text(clipboard);
|
||||
/* Reverse history if enabled */
|
||||
@ -913,9 +760,16 @@ show_history_menu_small(gpointer data)
|
||||
}
|
||||
}
|
||||
/* Make new item with ellipsized text */
|
||||
menu_item = gtk_menu_item_new_with_label(string->str);
|
||||
gchar* list_item;
|
||||
if (prefs.show_indexes)
|
||||
{
|
||||
list_item = g_strdup_printf("%" G_GINT64_FORMAT ". %s", (element_number_small+1), string->str);
|
||||
} else {
|
||||
list_item = g_strdup(string->str);
|
||||
}
|
||||
menu_item = gtk_menu_item_new_with_label(list_item);
|
||||
g_signal_connect((GObject*)menu_item, "activate",
|
||||
(GCallback)item_selected, (gpointer)(gint64)element_number);
|
||||
(GCallback)item_selected, (gpointer)element_number);
|
||||
|
||||
/* Modify menu item label properties */
|
||||
item_label = gtk_bin_get_child((GtkBin*)menu_item);
|
||||
@ -924,16 +778,17 @@ show_history_menu_small(gpointer data)
|
||||
/* Check if item is also clipboard text and make bold */
|
||||
if ((clipboard_temp) && (g_strcmp0((gchar*)element->data, clipboard_temp) == 0))
|
||||
{
|
||||
gchar* bold_text = g_markup_printf_escaped("<b>%s</b>", string->str);
|
||||
gchar* bold_text = g_markup_printf_escaped("<b>%s</b>", list_item);
|
||||
gtk_label_set_markup((GtkLabel*)item_label, bold_text);
|
||||
g_free(bold_text);
|
||||
}
|
||||
else if ((primary_temp) && (g_strcmp0((gchar*)element->data, primary_temp) == 0))
|
||||
{
|
||||
gchar* italic_text = g_markup_printf_escaped("<i>%s</i>", string->str);
|
||||
gchar* italic_text = g_markup_printf_escaped("<i>%s</i>", list_item);
|
||||
gtk_label_set_markup((GtkLabel*)item_label, italic_text);
|
||||
g_free(italic_text);
|
||||
}
|
||||
g_free(list_item);
|
||||
/* Append item */
|
||||
gtk_menu_shell_append((GtkMenuShell*)menu, menu_item);
|
||||
/* Prepare for next item */
|
||||
@ -942,7 +797,7 @@ show_history_menu_small(gpointer data)
|
||||
element_number--;
|
||||
else
|
||||
element_number++;
|
||||
element_number_small++;
|
||||
element_number_small++;
|
||||
}
|
||||
/* Cleanup */
|
||||
g_free(primary_temp);
|
||||
@ -959,7 +814,7 @@ show_history_menu_small(gpointer data)
|
||||
gtk_menu_shell_append((GtkMenuShell*)menu, menu_item);
|
||||
}
|
||||
/* -------------------- */
|
||||
/* Show full history (if enabled) */
|
||||
/* Show full history button (if enabled) */
|
||||
if (!prefs.full_hist_button)
|
||||
{
|
||||
gtk_menu_shell_append((GtkMenuShell*)menu, gtk_separator_menu_item_new());
|
||||
@ -1076,11 +931,13 @@ menu_hotkey(char *keystring, gpointer user_data)
|
||||
show_clipit_menu(status_icon, 0, 0, NULL);
|
||||
}
|
||||
|
||||
/* Called when actions global hotkey is pressed */
|
||||
/* Called when search global hotkey is pressed */
|
||||
void
|
||||
search_hotkey(char *keystring, gpointer user_data)
|
||||
{
|
||||
show_search();
|
||||
if (!gtk_grab_get_current())
|
||||
/* Show the search dialog */
|
||||
g_timeout_add(POPUP_DELAY, show_search, NULL);
|
||||
}
|
||||
|
||||
/* Startup calls and initializations */
|
||||
|
@ -35,6 +35,7 @@ typedef struct
|
||||
gboolean use_copy; /* Use copy */
|
||||
gboolean use_primary; /* Use primary */
|
||||
gboolean synchronize; /* Synchronize copy and primary */
|
||||
gboolean show_indexes; /* Show index numbers in history menu */
|
||||
|
||||
gboolean save_history; /* Save history */
|
||||
gint history_limit; /* Items in history */
|
||||
|
176
src/manage.c
Normal file
176
src/manage.c
Normal file
@ -0,0 +1,176 @@
|
||||
/* Copyright (C) 2010 by Cristian Henzel <oss@web-tm.com>
|
||||
*
|
||||
* forked from parcellite, which is
|
||||
* Copyright (C) 2007-2008 by Xyhthyx <xyhthyx@gmail.com>
|
||||
*
|
||||
* This file is part of ClipIt.
|
||||
*
|
||||
* ClipIt 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 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* ClipIt 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <glib.h>
|
||||
#include <gtk/gtk.h>
|
||||
#include "main.h"
|
||||
#include "utils.h"
|
||||
#include "history.h"
|
||||
#include "keybinder.h"
|
||||
#include "preferences.h"
|
||||
#include "clipit-i18n.h"
|
||||
|
||||
GtkListStore* search_list;
|
||||
GtkWidget *search_entry;
|
||||
GtkTreeSelection* search_selection;
|
||||
|
||||
static void
|
||||
search_doubleclick()
|
||||
{
|
||||
GtkTreeIter sel_iter;
|
||||
/* Check if selected */
|
||||
if (gtk_tree_selection_get_selected(search_selection, NULL, &sel_iter))
|
||||
{
|
||||
gchar *selected_item;
|
||||
gtk_tree_model_get((GtkTreeModel*)search_list, &sel_iter, 0, &selected_item, -1);
|
||||
GString* s_selected_item = g_string_new(selected_item);
|
||||
GtkClipboard* clip = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD);
|
||||
gtk_clipboard_set_text(clip, (gchar*)selected_item, -1);
|
||||
g_free(selected_item);
|
||||
g_string_free(s_selected_item, TRUE);
|
||||
}
|
||||
}
|
||||
|
||||
gint
|
||||
search_click(GtkWidget *widget, GdkEventButton *event, GtkWidget *search_window)
|
||||
{
|
||||
if(event->type==GDK_2BUTTON_PRESS || event->type==GDK_3BUTTON_PRESS)
|
||||
{
|
||||
search_doubleclick();
|
||||
gtk_widget_destroy(search_window);
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* Search through the history */
|
||||
static void
|
||||
search_history()
|
||||
{
|
||||
guint16 search_len = gtk_entry_get_text_length((GtkEntry*)search_entry);
|
||||
gchar* search_input = g_strdup(gtk_entry_get_text((GtkEntry*)search_entry));
|
||||
gchar* search_reg = g_regex_escape_string(search_input, search_len);
|
||||
gchar* search_regex = g_strconcat (".*", search_reg, ".*", NULL);
|
||||
GRegex* regex = g_regex_new(search_regex, G_REGEX_CASELESS, 0, NULL);
|
||||
GtkTreeIter search_iter;
|
||||
while(gtk_tree_model_get_iter_first((GtkTreeModel*)search_list, &search_iter))
|
||||
gtk_list_store_remove(search_list, &search_iter);
|
||||
/* Test if there is text in the search box */
|
||||
if(search_len > 0)
|
||||
{
|
||||
if ((history != NULL) && (history->data != NULL))
|
||||
{
|
||||
/* Declare some variables */
|
||||
GSList* element;
|
||||
gint element_number = 0;
|
||||
/* Go through each element and adding each */
|
||||
for (element = history; element != NULL; element = element->next)
|
||||
{
|
||||
GString* string = g_string_new((gchar*)element->data);
|
||||
gchar* compare = string->str;
|
||||
gboolean result = g_regex_match(regex, compare, 0, NULL);
|
||||
if(result)
|
||||
{
|
||||
GtkTreeIter row_iter;
|
||||
gtk_list_store_append(search_list, &row_iter);
|
||||
gtk_list_store_set(search_list, &row_iter, 0, string->str, -1);
|
||||
}
|
||||
/* Prepare for next item */
|
||||
g_string_free(string, TRUE);
|
||||
element_number++;
|
||||
}
|
||||
}
|
||||
g_regex_unref(regex);
|
||||
}
|
||||
g_free(search_regex);
|
||||
}
|
||||
|
||||
static gint
|
||||
search_key_pressed(GtkWidget *widget, GdkEventKey *event, gpointer user_data)
|
||||
{
|
||||
/* Check if [Return] key was pressed */
|
||||
if ((event->keyval == 0xff0d) || (event->keyval == 0xff8d))
|
||||
search_history();
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* Shows the search dialog */
|
||||
gboolean
|
||||
show_search()
|
||||
{
|
||||
/* Declare some variables */
|
||||
GtkWidget *frame, *label,
|
||||
*alignment, *hbox,
|
||||
*vbox;
|
||||
|
||||
GtkTreeViewColumn *tree_column;
|
||||
|
||||
/* Create the dialog */
|
||||
GtkWidget* search_dialog = gtk_dialog_new_with_buttons(_("Search"), NULL,
|
||||
GTK_DIALOG_DESTROY_WITH_PARENT,
|
||||
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, NULL);
|
||||
|
||||
gtk_window_set_icon((GtkWindow*)search_dialog, gtk_widget_render_icon(search_dialog, GTK_STOCK_FIND, GTK_ICON_SIZE_MENU, NULL));
|
||||
gtk_window_set_resizable((GtkWindow*)search_dialog, TRUE);
|
||||
gtk_window_set_position((GtkWindow*)search_dialog, GTK_WIN_POS_CENTER);
|
||||
|
||||
GtkWidget* vbox_search = gtk_vbox_new(FALSE, 12);
|
||||
gtk_box_pack_start(GTK_BOX(gtk_dialog_get_content_area (GTK_DIALOG(search_dialog))), vbox_search, TRUE, TRUE, 2);
|
||||
gtk_widget_set_size_request((GtkWidget*)vbox_search, 400, 600);
|
||||
|
||||
hbox = gtk_hbox_new(TRUE, 4);
|
||||
gtk_box_pack_start((GtkBox*)vbox_search, hbox, FALSE, FALSE, 0);
|
||||
search_entry = gtk_entry_new();
|
||||
gtk_box_pack_end((GtkBox*)hbox, search_entry, TRUE, TRUE, 0);
|
||||
g_signal_connect((GObject*)search_entry, "key-press-event", (GCallback)search_key_pressed, NULL);
|
||||
|
||||
/* Build the exclude treeview */
|
||||
GtkWidget* scrolled_window_search = gtk_scrolled_window_new(
|
||||
(GtkAdjustment*)gtk_adjustment_new(0, 0, 0, 0, 0, 0),
|
||||
(GtkAdjustment*)gtk_adjustment_new(0, 0, 0, 0, 0, 0));
|
||||
|
||||
gtk_scrolled_window_set_policy((GtkScrolledWindow*)scrolled_window_search, GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
|
||||
gtk_scrolled_window_set_shadow_type((GtkScrolledWindow*)scrolled_window_search, GTK_SHADOW_ETCHED_OUT);
|
||||
GtkWidget* treeview_search = gtk_tree_view_new();
|
||||
gtk_tree_view_set_reorderable((GtkTreeView*)treeview_search, TRUE);
|
||||
gtk_tree_view_set_rules_hint((GtkTreeView*)treeview_search, TRUE);
|
||||
search_list = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_STRING);
|
||||
gtk_tree_view_set_model((GtkTreeView*)treeview_search, (GtkTreeModel*)search_list);
|
||||
GtkCellRenderer* name_renderer_exclude = gtk_cell_renderer_text_new();
|
||||
g_object_set(name_renderer_exclude, "ellipsize", PANGO_ELLIPSIZE_END, NULL);
|
||||
g_object_set(name_renderer_exclude, "single-paragraph-mode", TRUE, NULL);
|
||||
tree_column = gtk_tree_view_column_new_with_attributes(_("Results"), name_renderer_exclude, "text", 0, NULL);
|
||||
gtk_tree_view_column_set_resizable(tree_column, TRUE);
|
||||
gtk_tree_view_append_column((GtkTreeView*)treeview_search, tree_column);
|
||||
gtk_container_add((GtkContainer*)scrolled_window_search, treeview_search);
|
||||
gtk_box_pack_start((GtkBox*)vbox_search, scrolled_window_search, TRUE, TRUE, 0);
|
||||
|
||||
search_selection = gtk_tree_view_get_selection((GtkTreeView*)treeview_search);
|
||||
gtk_tree_selection_set_mode(search_selection, GTK_SELECTION_BROWSE);
|
||||
g_signal_connect((GObject*)treeview_search, "button_press_event", (GCallback)search_click, search_dialog);
|
||||
|
||||
g_signal_connect((GtkDialog*)search_dialog, "response", (GCallback)gtk_widget_destroy, search_dialog);
|
||||
gtk_widget_show_all(vbox_search);
|
||||
|
||||
/* show the dialog */
|
||||
gtk_widget_show_all((GtkWidget*)search_dialog);
|
||||
|
||||
return FALSE;
|
||||
}
|
32
src/manage.h
Normal file
32
src/manage.h
Normal file
@ -0,0 +1,32 @@
|
||||
/* Copyright (C) 2010 by Cristian Henzel <oss@web-tm.com>
|
||||
*
|
||||
* forked from parcellite, which is
|
||||
* Copyright (C) 2007-2008 by Xyhthyx <xyhthyx@gmail.com>
|
||||
*
|
||||
* This file is part of ClipIt.
|
||||
*
|
||||
* ClipIt 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 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* ClipIt 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef MANAGE_H
|
||||
#define MANAGE_H
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
gboolean
|
||||
show_search();
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif
|
@ -32,6 +32,7 @@
|
||||
GtkWidget *copy_check,
|
||||
*primary_check,
|
||||
*synchronize_check,
|
||||
*show_indexes_check,
|
||||
*full_hist_check,
|
||||
*history_spin,
|
||||
*history_small,
|
||||
@ -75,6 +76,7 @@ apply_preferences()
|
||||
prefs.use_copy = gtk_toggle_button_get_active((GtkToggleButton*)copy_check);
|
||||
prefs.use_primary = gtk_toggle_button_get_active((GtkToggleButton*)primary_check);
|
||||
prefs.synchronize = gtk_toggle_button_get_active((GtkToggleButton*)synchronize_check);
|
||||
prefs.show_indexes = gtk_toggle_button_get_active((GtkToggleButton*)show_indexes_check);
|
||||
prefs.save_history = gtk_toggle_button_get_active((GtkToggleButton*)save_check);
|
||||
prefs.history_limit = gtk_spin_button_get_value_as_int((GtkSpinButton*)history_spin);
|
||||
prefs.small_history = gtk_toggle_button_get_active((GtkToggleButton*)small_check);
|
||||
@ -110,6 +112,7 @@ save_preferences()
|
||||
g_key_file_set_boolean(rc_key, "rc", "use_copy", prefs.use_copy);
|
||||
g_key_file_set_boolean(rc_key, "rc", "use_primary", prefs.use_primary);
|
||||
g_key_file_set_boolean(rc_key, "rc", "synchronize", prefs.synchronize);
|
||||
g_key_file_set_boolean(rc_key, "rc", "show_indexes", prefs.show_indexes);
|
||||
g_key_file_set_boolean(rc_key, "rc", "save_history", prefs.save_history);
|
||||
g_key_file_set_integer(rc_key, "rc", "history_limit", prefs.history_limit);
|
||||
g_key_file_set_boolean(rc_key, "rc", "small_history", prefs.small_history);
|
||||
@ -148,6 +151,7 @@ read_preferences()
|
||||
prefs.use_copy = g_key_file_get_boolean(rc_key, "rc", "use_copy", NULL);
|
||||
prefs.use_primary = g_key_file_get_boolean(rc_key, "rc", "use_primary", NULL);
|
||||
prefs.synchronize = g_key_file_get_boolean(rc_key, "rc", "synchronize", NULL);
|
||||
prefs.show_indexes = g_key_file_get_boolean(rc_key, "rc", "show_indexes", NULL);
|
||||
prefs.save_history = g_key_file_get_boolean(rc_key, "rc", "save_history", NULL);
|
||||
prefs.history_limit = g_key_file_get_integer(rc_key, "rc", "history_limit", NULL);
|
||||
prefs.small_history = g_key_file_get_boolean(rc_key, "rc", "small_history", NULL);
|
||||
@ -603,6 +607,8 @@ show_preferences(gint tab)
|
||||
gtk_box_pack_start((GtkBox*)vbox, primary_check, FALSE, FALSE, 0);
|
||||
synchronize_check = gtk_check_button_new_with_mnemonic(_("S_ynchronize clipboards"));
|
||||
gtk_box_pack_start((GtkBox*)vbox, synchronize_check, FALSE, FALSE, 0);
|
||||
show_indexes_check = gtk_check_button_new_with_mnemonic(_("S_how indexes in history menu"));
|
||||
gtk_box_pack_start((GtkBox*)vbox, show_indexes_check, FALSE, FALSE, 0);
|
||||
gtk_box_pack_start((GtkBox*)vbox_behavior, frame, FALSE, FALSE, 0);
|
||||
|
||||
/* Build the history frame */
|
||||
@ -910,6 +916,7 @@ show_preferences(gint tab)
|
||||
gtk_toggle_button_set_active((GtkToggleButton*)copy_check, prefs.use_copy);
|
||||
gtk_toggle_button_set_active((GtkToggleButton*)primary_check, prefs.use_primary);
|
||||
gtk_toggle_button_set_active((GtkToggleButton*)synchronize_check, prefs.synchronize);
|
||||
gtk_toggle_button_set_active((GtkToggleButton*)show_indexes_check, prefs.show_indexes);
|
||||
gtk_toggle_button_set_active((GtkToggleButton*)save_check, prefs.save_history);
|
||||
gtk_spin_button_set_value((GtkSpinButton*)history_spin, (gdouble)prefs.history_limit);
|
||||
gtk_toggle_button_set_active((GtkToggleButton*)small_check, prefs.small_history);
|
||||
|
@ -32,6 +32,7 @@ G_BEGIN_DECLS
|
||||
#define DEF_USE_COPY TRUE
|
||||
#define DEF_USE_PRIMARY FALSE
|
||||
#define DEF_SYNCHRONIZE FALSE
|
||||
#define DEF_SHOW_INDEXES FALSE
|
||||
#define DEF_SAVE_HISTORY TRUE
|
||||
#define DEF_HISTORY_LIMIT 25
|
||||
#define DEF_SMALL_HISTORY TRUE
|
||||
|
Loading…
Reference in New Issue
Block a user