From 5d567d72ec56ab329e17db29d9cce47b4f9f1858 Mon Sep 17 00:00:00 2001 From: Cristian Henzel Date: Wed, 18 May 2011 15:24:54 +0300 Subject: [PATCH] ClipIt-1.4.0-20110518001 + Fixed: Re-enabled indicator support. + Added: We are now installing a sepparate icon for clipit (not using it yet, though). + Added: Search as you type in "Manage history" dialog. + Added: 1-0 shortcuts for fast selecting of menu items. + Added: Possiblity to select multiple items for deletion in the "Manage history" dialog. Changes to be committed: modified: ChangeLog modified: Makefile.am modified: Makefile.in modified: TODO modified: configure modified: configure.in modified: data/Makefile.am modified: data/Makefile.in new file: data/trayicon.svg modified: src/Makefile.am modified: src/Makefile.in modified: src/main.c modified: src/manage.c --- ChangeLog | 9 +++ Makefile.am | 1 + Makefile.in | 1 + TODO | 2 + configure | 22 +++--- configure.in | 4 +- data/Makefile.am | 6 +- data/Makefile.in | 48 +++++++++--- data/trayicon.svg | 191 ++++++++++++++++++++++++++++++++++++++++++++++ src/Makefile.am | 20 ++--- src/Makefile.in | 21 ++--- src/main.c | 88 ++++++++++++++++----- src/manage.c | 69 +++++++++++------ 13 files changed, 394 insertions(+), 88 deletions(-) create mode 100644 data/trayicon.svg diff --git a/ChangeLog b/ChangeLog index 4c66b1f..55b38c3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +ClipIt-1.4.0-20110518001 - 18 May. 2011 + + Fixed: Re-enabled indicator support. + + Added: We are now installing a sepparate icon for clipit (not using it + yet, though). + + Added: Search as you type in "Manage history" dialog. + + Added: 1-0 shortcuts for fast selecting of menu items. + + Added: Possiblity to select multiple items for deletion in the + "Manage history" dialog. + ClipIt-1.4.0-20110506001 - 06 May. 2011 + Added: Added option to automatically paste an entry after selecting it. + Fixed: Re-enabled indicator since it should now work properly. diff --git a/Makefile.am b/Makefile.am index 258eb28..3465d7b 100644 --- a/Makefile.am +++ b/Makefile.am @@ -11,6 +11,7 @@ EXTRA_DIST = \ m4/ChangeLog \ $(desktop_DATA) \ $(autostart_DATA) \ + $(pixmaps_DATA) \ intltool-merge.in \ intltool-update.in \ intltool-extract.in diff --git a/Makefile.in b/Makefile.in index d587e98..f58ad44 100644 --- a/Makefile.in +++ b/Makefile.in @@ -259,6 +259,7 @@ EXTRA_DIST = \ m4/ChangeLog \ $(desktop_DATA) \ $(autostart_DATA) \ + $(pixmaps_DATA) \ intltool-merge.in \ intltool-update.in \ intltool-extract.in diff --git a/TODO b/TODO index 04aeb1b..9f03a39 100644 --- a/TODO +++ b/TODO @@ -5,3 +5,5 @@ + Redo Preferences dialog. + Clean up the code and indent it properly. + Move all pop-up and menu functions from main.c to menus.c. ++ Use the shipped icon in the display. ++ Fix the allowed keys in the manage history dialog. diff --git a/configure b/configure index 14c8957..f51bbfd 100644 --- a/configure +++ b/configure @@ -1,6 +1,6 @@ #! /bin/sh # Guess values for system-dependent variables and create Makefiles. -# Generated by GNU Autoconf 2.67 for clipit 1.3.13. +# Generated by GNU Autoconf 2.67 for clipit 1.4.0. # # Report bugs to . # @@ -552,8 +552,8 @@ MAKEFLAGS= # Identity of this package. PACKAGE_NAME='clipit' PACKAGE_TARNAME='clipit' -PACKAGE_VERSION='1.3.13' -PACKAGE_STRING='clipit 1.3.13' +PACKAGE_VERSION='1.4.0' +PACKAGE_STRING='clipit 1.4.0' PACKAGE_BUGREPORT='oss@rspwn.com' PACKAGE_URL='' @@ -1328,7 +1328,7 @@ if test "$ac_init_help" = "long"; then # Omit some internal or obsolete options to make the list less imposing. # This message is too long to be a string in the A/UX 3.1 sh. cat <<_ACEOF -\`configure' configures clipit 1.3.13 to adapt to many kinds of systems. +\`configure' configures clipit 1.4.0 to adapt to many kinds of systems. Usage: $0 [OPTION]... [VAR=VALUE]... @@ -1398,7 +1398,7 @@ fi if test -n "$ac_init_help"; then case $ac_init_help in - short | recursive ) echo "Configuration of clipit 1.3.13:";; + short | recursive ) echo "Configuration of clipit 1.4.0:";; esac cat <<\_ACEOF @@ -1511,7 +1511,7 @@ fi test -n "$ac_init_help" && exit $ac_status if $ac_init_version; then cat <<\_ACEOF -clipit configure 1.3.13 +clipit configure 1.4.0 generated by GNU Autoconf 2.67 Copyright (C) 2010 Free Software Foundation, Inc. @@ -1880,7 +1880,7 @@ cat >config.log <<_ACEOF This file contains any messages produced by compilers while running configure, to aid debugging if configure makes a mistake. -It was created by clipit $as_me 1.3.13, which was +It was created by clipit $as_me 1.4.0, which was generated by GNU Autoconf 2.67. Invocation command line was $ $0 $@ @@ -2696,7 +2696,7 @@ fi # Define the identity of the package. PACKAGE=clipit - VERSION=1.3.13 + VERSION=1.4.0 cat >>confdefs.h <<_ACEOF @@ -7487,7 +7487,7 @@ APPINDICATOR_REQUIRED_VERSION=0.2.4 if test "${enable_appindicator+set}" = set; then : enableval=$enable_appindicator; enable_appindicator=$enableval else - enable_appindicator="no" + enable_appindicator="auto" fi @@ -9764,7 +9764,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 # report actual input values of CONFIG_FILES etc. instead of their # values after options handling. ac_log=" -This file was extended by clipit $as_me 1.3.13, which was +This file was extended by clipit $as_me 1.4.0, which was generated by GNU Autoconf 2.67. Invocation command line was CONFIG_FILES = $CONFIG_FILES @@ -9830,7 +9830,7 @@ _ACEOF cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`" ac_cs_version="\\ -clipit config.status 1.3.13 +clipit config.status 1.4.0 configured by $0, generated by GNU Autoconf 2.67, with options \\"\$ac_cs_config\\" diff --git a/configure.in b/configure.in index b285c46..bf35536 100644 --- a/configure.in +++ b/configure.in @@ -2,7 +2,7 @@ # Autoconf/automake. # ------------------------------------------------------------------------------- AC_PREREQ([2.5]) -AC_INIT([clipit], [1.3.13], [oss@rspwn.com]) +AC_INIT([clipit], [1.4.0], [oss@rspwn.com]) AM_INIT_AUTOMAKE([AC_PACKAGE_TARNAME()], [AC_PACKAGE_VERSION()]) AC_CONFIG_MACRO_DIR([m4]) @@ -37,7 +37,7 @@ APPINDICATOR_REQUIRED_VERSION=0.2.4 AC_ARG_ENABLE([appindicator], AS_HELP_STRING([--enable-appindicator[=@<:@no/auto/yes@:>@]],[Build support for application indicators]), [enable_appindicator=$enableval], - [enable_appindicator="no"]) + [enable_appindicator="auto"]) if test x$enable_appindicator = xauto ; then diff --git a/data/Makefile.am b/data/Makefile.am index be564c2..f9baacd 100644 --- a/data/Makefile.am +++ b/data/Makefile.am @@ -8,9 +8,13 @@ autostartdir = $(sysconfdir)/xdg/autostart autostart_in_file = clipit-startup.desktop.in autostart_DATA = $(autostart_in_file:.desktop.in=.desktop) +pixmapsdir = $(datarootdir)/pixmaps/clipit +pixmaps_DATA = trayicon.svg + EXTRA_DIST = \ $(desktop_in_file) \ - $(autostart_in_file) + $(autostart_in_file) \ + $(pixmaps_DATA) CLEANFILES = \ $(desktop_DATA) \ diff --git a/data/Makefile.in b/data/Makefile.in index 9116eb6..7d9b323 100644 --- a/data/Makefile.in +++ b/data/Makefile.in @@ -73,8 +73,8 @@ am__base_list = \ sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \ sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g' am__installdirs = "$(DESTDIR)$(autostartdir)" \ - "$(DESTDIR)$(desktopdir)" -DATA = $(autostart_DATA) $(desktop_DATA) + "$(DESTDIR)$(desktopdir)" "$(DESTDIR)$(pixmapsdir)" +DATA = $(autostart_DATA) $(desktop_DATA) $(pixmaps_DATA) DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) ACLOCAL = @ACLOCAL@ ALL_LINGUAS = @ALL_LINGUAS@ @@ -224,9 +224,12 @@ desktop_DATA = $(desktop_in_file:.desktop.in=.desktop) autostartdir = $(sysconfdir)/xdg/autostart autostart_in_file = clipit-startup.desktop.in autostart_DATA = $(autostart_in_file:.desktop.in=.desktop) +pixmapsdir = $(datarootdir)/pixmaps/clipit +pixmaps_DATA = trayicon.svg EXTRA_DIST = \ $(desktop_in_file) \ - $(autostart_in_file) + $(autostart_in_file) \ + $(pixmaps_DATA) CLEANFILES = \ $(desktop_DATA) \ @@ -309,6 +312,26 @@ uninstall-desktopDATA: test -n "$$files" || exit 0; \ echo " ( cd '$(DESTDIR)$(desktopdir)' && rm -f" $$files ")"; \ cd "$(DESTDIR)$(desktopdir)" && rm -f $$files +install-pixmapsDATA: $(pixmaps_DATA) + @$(NORMAL_INSTALL) + test -z "$(pixmapsdir)" || $(MKDIR_P) "$(DESTDIR)$(pixmapsdir)" + @list='$(pixmaps_DATA)'; test -n "$(pixmapsdir)" || list=; \ + for p in $$list; do \ + if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \ + echo "$$d$$p"; \ + done | $(am__base_list) | \ + while read files; do \ + echo " $(INSTALL_DATA) $$files '$(DESTDIR)$(pixmapsdir)'"; \ + $(INSTALL_DATA) $$files "$(DESTDIR)$(pixmapsdir)" || exit $$?; \ + done + +uninstall-pixmapsDATA: + @$(NORMAL_UNINSTALL) + @list='$(pixmaps_DATA)'; test -n "$(pixmapsdir)" || list=; \ + files=`for p in $$list; do echo $$p; done | sed -e 's|^.*/||'`; \ + test -n "$$files" || exit 0; \ + echo " ( cd '$(DESTDIR)$(pixmapsdir)' && rm -f" $$files ")"; \ + cd "$(DESTDIR)$(pixmapsdir)" && rm -f $$files tags: TAGS TAGS: @@ -350,7 +373,7 @@ check-am: all-am check: check-am all-am: Makefile $(DATA) installdirs: - for dir in "$(DESTDIR)$(autostartdir)" "$(DESTDIR)$(desktopdir)"; do \ + for dir in "$(DESTDIR)$(autostartdir)" "$(DESTDIR)$(desktopdir)" "$(DESTDIR)$(pixmapsdir)"; do \ test -z "$$dir" || $(MKDIR_P) "$$dir"; \ done install: install-am @@ -400,7 +423,8 @@ info: info-am info-am: -install-data-am: install-autostartDATA install-desktopDATA +install-data-am: install-autostartDATA install-desktopDATA \ + install-pixmapsDATA install-dvi: install-dvi-am @@ -444,7 +468,8 @@ ps: ps-am ps-am: -uninstall-am: uninstall-autostartDATA uninstall-desktopDATA +uninstall-am: uninstall-autostartDATA uninstall-desktopDATA \ + uninstall-pixmapsDATA .MAKE: install-am install-strip @@ -454,11 +479,12 @@ uninstall-am: uninstall-autostartDATA uninstall-desktopDATA install-data-am install-desktopDATA install-dvi install-dvi-am \ install-exec install-exec-am install-html install-html-am \ install-info install-info-am install-man install-pdf \ - install-pdf-am install-ps install-ps-am install-strip \ - installcheck installcheck-am installdirs maintainer-clean \ - maintainer-clean-generic mostlyclean mostlyclean-generic pdf \ - pdf-am ps ps-am uninstall uninstall-am uninstall-autostartDATA \ - uninstall-desktopDATA + install-pdf-am install-pixmapsDATA install-ps install-ps-am \ + install-strip installcheck installcheck-am installdirs \ + maintainer-clean maintainer-clean-generic mostlyclean \ + mostlyclean-generic pdf pdf-am ps ps-am uninstall uninstall-am \ + uninstall-autostartDATA uninstall-desktopDATA \ + uninstall-pixmapsDATA @INTLTOOL_DESKTOP_RULE@ diff --git a/data/trayicon.svg b/data/trayicon.svg new file mode 100644 index 0000000..0504856 --- /dev/null +++ b/data/trayicon.svg @@ -0,0 +1,191 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Makefile.am b/src/Makefile.am index 5829907..33038ea 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,4 +1,6 @@ -AM_CFLAGS = -I$(top_srcdir) -DCLIPITLOCALEDIR=\""$(clipitlocaledir)"\" +AM_CPPFLAGS = -I$(top_srcdir) +AM_CFLAGS = -DCLIPITLOCALEDIR=\""$(clipitlocaledir)"\" \ + -DCLIPITPIXMAPSDIR=\""$(datarootdir)"/pixmaps/clipit\" INCLUDES = $(GTK_CFLAGS) $(APPINDICATOR_CFLAGS) LDADD = $(GTK_LIBS) $(APPINDICATOR_LIBS) $(X11_LIBS) AM_LDFLAGS = -Wl,--as-needed @@ -8,11 +10,11 @@ bin_PROGRAMS = clipit DISTCLEANFILES = *.bak *.log *~ .deps/*.P clipit_SOURCES = main.c main.h \ - utils.c utils.h \ - clipit-i18n.h\ - daemon.c daemon.h \ - history.c history.h \ - keybinder.c keybinder.h \ - preferences.c preferences.h \ - manage.c manage.h \ - eggaccelerators.c eggaccelerators.h + utils.c utils.h \ + clipit-i18n.h\ + daemon.c daemon.h \ + history.c history.h \ + keybinder.c keybinder.h \ + preferences.c preferences.h \ + manage.c manage.h \ + eggaccelerators.c eggaccelerators.h diff --git a/src/Makefile.in b/src/Makefile.in index 2f6528e..48e8728 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -215,20 +215,23 @@ target_alias = @target_alias@ top_build_prefix = @top_build_prefix@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ -AM_CFLAGS = -I$(top_srcdir) -DCLIPITLOCALEDIR=\""$(clipitlocaledir)"\" +AM_CPPFLAGS = -I$(top_srcdir) +AM_CFLAGS = -DCLIPITLOCALEDIR=\""$(clipitlocaledir)"\" \ + -DCLIPITPIXMAPSDIR=\""$(datarootdir)"/pixmaps/clipit\" + INCLUDES = $(GTK_CFLAGS) $(APPINDICATOR_CFLAGS) LDADD = $(GTK_LIBS) $(APPINDICATOR_LIBS) $(X11_LIBS) AM_LDFLAGS = -Wl,--as-needed DISTCLEANFILES = *.bak *.log *~ .deps/*.P clipit_SOURCES = main.c main.h \ - utils.c utils.h \ - clipit-i18n.h\ - daemon.c daemon.h \ - history.c history.h \ - keybinder.c keybinder.h \ - preferences.c preferences.h \ - manage.c manage.h \ - eggaccelerators.c eggaccelerators.h + utils.c utils.h \ + clipit-i18n.h\ + daemon.c daemon.h \ + history.c history.h \ + keybinder.c keybinder.h \ + preferences.c preferences.h \ + manage.c manage.h \ + eggaccelerators.c eggaccelerators.h all: all-am diff --git a/src/main.c b/src/main.c index af9f74b..4245b68 100644 --- a/src/main.c +++ b/src/main.c @@ -55,13 +55,13 @@ static gboolean status_menu_lock = FALSE; static gboolean actions_lock = FALSE; /* Init preferences structure */ -prefs_t prefs = {DEF_USE_COPY, DEF_USE_PRIMARY, DEF_SYNCHRONIZE, - DEF_SHOW_INDEXES, DEF_SAVE_URIS, DEF_SAVE_HISTORY, - DEF_HISTORY_LIMIT, DEF_ITEMS_MENU, DEF_HYPERLINKS_ONLY, - DEF_CONFIRM_CLEAR, DEF_SINGLE_LINE, DEF_REVERSE_HISTORY, - DEF_ITEM_LENGTH, DEF_ELLIPSIZE, INIT_HISTORY_KEY, - INIT_ACTIONS_KEY, INIT_MENU_KEY, INIT_SEARCH_KEY, - DEF_NO_ICON}; +prefs_t prefs = {DEF_USE_COPY, DEF_USE_PRIMARY, DEF_SYNCHRONIZE, + DEF_AUTOMATIC_PASTE, DEF_SHOW_INDEXES, DEF_SAVE_URIS, + DEF_SAVE_HISTORY, DEF_HISTORY_LIMIT, DEF_ITEMS_MENU, + DEF_HYPERLINKS_ONLY, DEF_CONFIRM_CLEAR, DEF_SINGLE_LINE, + DEF_REVERSE_HISTORY, DEF_ITEM_LENGTH, DEF_ELLIPSIZE, + INIT_HISTORY_KEY, INIT_ACTIONS_KEY, INIT_MENU_KEY, + INIT_SEARCH_KEY, DEF_NO_ICON}; /* Called every CHECK_INTERVAL seconds to check for new items */ static gboolean item_check(gpointer data) @@ -128,7 +128,7 @@ static gboolean item_check(gpointer data) } } } - + /* Check if clipboard contents were lost */ if ((clipboard_temp == NULL) && (clipboard_text != NULL)) { @@ -169,7 +169,7 @@ static gboolean item_check(gpointer data) } } } - + /* Synchronization */ if (prefs.synchronize) { @@ -186,7 +186,7 @@ static gboolean item_check(gpointer data) gtk_clipboard_set_text(primary, clipboard_text, -1); } } - + /* Cleanup */ g_free(primary_temp); g_free(clipboard_temp); @@ -229,7 +229,7 @@ static void action_selected(GtkButton *button, gpointer user_data) g_free(command); gchar* cmd = g_strconcat("/bin/sh -c ", shell_command, NULL); g_free(shell_command); - + /* Execute action */ GPid pid; gchar **argv; @@ -302,22 +302,22 @@ static void show_about_dialog(GtkMenuItem *menu_item, gpointer user_data) "\n" "You should have received a copy of the GNU General Public License\n" "along with this program. If not, see ."; - + /* Create the about dialog */ GtkWidget* about_dialog = gtk_about_dialog_new(); gtk_window_set_icon((GtkWindow*)about_dialog, gtk_widget_render_icon(about_dialog, GTK_STOCK_ABOUT, GTK_ICON_SIZE_MENU, NULL)); - + gtk_about_dialog_set_name((GtkAboutDialog*)about_dialog, "ClipIt"); #ifdef HAVE_CONFIG_H gtk_about_dialog_set_version((GtkAboutDialog*)about_dialog, VERSION); #endif gtk_about_dialog_set_comments((GtkAboutDialog*)about_dialog, _("Lightweight GTK+ clipboard manager.")); - + gtk_about_dialog_set_website((GtkAboutDialog*)about_dialog, "http://clipit.rspwn.com/"); - + gtk_about_dialog_set_copyright((GtkAboutDialog*)about_dialog, "Copyright (C) 2010 Cristian Henzel"); gtk_about_dialog_set_authors((GtkAboutDialog*)about_dialog, authors); gtk_about_dialog_set_translator_credits ((GtkAboutDialog*)about_dialog, @@ -339,7 +339,7 @@ static void show_about_dialog(GtkMenuItem *menu_item, gpointer user_data) "Hedef Türkçe \n" "Lyman Li \n" "Gilberto \"Xyhthyx\" Miralla "); - + gtk_about_dialog_set_license((GtkAboutDialog*)about_dialog, license); gtk_about_dialog_set_logo_icon_name((GtkAboutDialog*)about_dialog, GTK_STOCK_PASTE); /* Run the about dialog */ @@ -372,7 +372,7 @@ static gboolean show_actions_menu(gpointer data) /* Declare some variables */ GtkWidget *menu, *menu_item, *menu_image, *item_label; - + /* Create menu */ menu = gtk_menu_new(); g_signal_connect((GObject*)menu, "selection-done", (GCallback)gtk_widget_destroy, NULL); @@ -518,11 +518,11 @@ static gboolean show_history_menu(gpointer data) } menu_item = gtk_menu_item_new_with_label(list_item); g_signal_connect((GObject*)menu_item, "activate", (GCallback)item_selected, GINT_TO_POINTER(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); - + /* Check if item is also clipboard text and make bold */ if ((clipboard_temp) && (g_strcmp0((gchar*)element->data, clipboard_temp) == 0)) { @@ -569,6 +569,53 @@ static gboolean show_history_menu(gpointer data) return FALSE; } +static gboolean menu_key_pressed(GtkWidget *widget, GdkEventKey *event, gpointer user_data) +{ + switch (event->keyval) { + case 0x0030: + item_selected((GtkMenuItem*)widget, GINT_TO_POINTER(9)); + gtk_widget_destroy(widget); + break; + case 0x0031: + item_selected((GtkMenuItem*)widget, GINT_TO_POINTER(0)); + gtk_widget_destroy(widget); + break; + case 0x0032: + item_selected((GtkMenuItem*)widget, GINT_TO_POINTER(1)); + gtk_widget_destroy(widget); + break; + case 0x0033: + item_selected((GtkMenuItem*)widget, GINT_TO_POINTER(2)); + gtk_widget_destroy(widget); + break; + case 0x0034: + item_selected((GtkMenuItem*)widget, GINT_TO_POINTER(3)); + gtk_widget_destroy(widget); + break; + case 0x0035: + item_selected((GtkMenuItem*)widget, GINT_TO_POINTER(4)); + gtk_widget_destroy(widget); + break; + case 0x0036: + item_selected((GtkMenuItem*)widget, GINT_TO_POINTER(5)); + gtk_widget_destroy(widget); + break; + case 0x0037: + item_selected((GtkMenuItem*)widget, GINT_TO_POINTER(6)); + gtk_widget_destroy(widget); + break; + case 0x0038: + item_selected((GtkMenuItem*)widget, GINT_TO_POINTER(7)); + gtk_widget_destroy(widget); + break; + case 0x0039: + item_selected((GtkMenuItem*)widget, GINT_TO_POINTER(8)); + gtk_widget_destroy(widget); + break; + } + return FALSE; +} + #ifdef HAVE_APPINDICATOR void create_app_indicator(gint create) @@ -704,6 +751,7 @@ static gboolean show_clipit_menu() /* Create the menu */ statusicon_menu = gtk_menu_new(); g_signal_connect((GObject*)statusicon_menu, "selection-done", (GCallback)gtk_widget_destroy, NULL); + g_signal_connect((GObject*)statusicon_menu, "key-press-event", (GCallback)menu_key_pressed, NULL); /* Items */ if ((history != NULL) && (history->data != NULL)) @@ -947,7 +995,7 @@ int main(int argc, char **argv) g_string_free(piped_string, TRUE); } } - + /* Init ClipIt */ clipit_init(); diff --git a/src/manage.c b/src/manage.c index 1c60081..73f8e13 100644 --- a/src/manage.c +++ b/src/manage.c @@ -107,13 +107,18 @@ static void edit_selected() { GtkTreeIter sel_iter; GtkTreeSelection* search_selection = gtk_tree_view_get_selection((GtkTreeView*)treeview_search); - /* This helps prevent multiple instances and checks if there's anything selected */ - if (gtk_tree_selection_get_selected(search_selection, NULL, &sel_iter)) - { + /* This checks if there's anything selected */ + gint selected_count = gtk_tree_selection_count_selected_rows(search_selection); + if (selected_count > 0) { /* Create clipboard buffer and set its text */ gint selected_item_nr; - gtk_tree_model_get((GtkTreeModel*)search_list, &sel_iter, 0, &selected_item_nr, -1); + GList *selected_rows = gtk_tree_selection_get_selected_rows(search_selection, NULL); + GList *row_loop = g_list_first(selected_rows); + selected_item_nr = atoi((gchar*)gtk_tree_path_to_string(row_loop->data)); + g_list_foreach(selected_rows, (GFunc)gtk_tree_path_free, NULL); + g_list_free(selected_rows); GSList* element = g_slist_nth(history, selected_item_nr); + GSList* elementafter = element->next; GString* s_selected_item = g_string_new((gchar*)element->data); GtkTextBuffer* clipboard_buffer = gtk_text_buffer_new(NULL); gtk_text_buffer_set_text(clipboard_buffer, s_selected_item->str, -1); @@ -151,13 +156,13 @@ static void edit_selected() /* Delete any duplicate */ delete_duplicate(gtk_text_buffer_get_text(clipboard_buffer, &start, &end, TRUE)); - /* Insert new element before the old one */ - history = g_slist_insert_before(history, element->next, - g_strdup(gtk_text_buffer_get_text(clipboard_buffer, &start, &end, TRUE))); - /* Remove old entry */ history = g_slist_remove(history, element->data); + /* Insert new element where the old one was */ + history = g_slist_insert_before(history, elementafter, + g_strdup(gtk_text_buffer_get_text(clipboard_buffer, &start, &end, TRUE))); + if(selected_item_nr == 0) { GtkClipboard* clipboard; @@ -173,21 +178,31 @@ static void edit_selected() } } +static void add_iter(GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *piter, gpointer userdata) +{ + GArray *sel = (GArray*)userdata; + GtkTreeIter iter = *piter; + g_array_append_val(sel, iter); +} + /* Called when Remove is selected from Manage dialog */ static void remove_selected() { - GtkTreeIter sel_iter; GtkTreeSelection* search_selection = gtk_tree_view_get_selection((GtkTreeView*)treeview_search); - /* This checks if there's anything selected */ - if (gtk_tree_selection_get_selected(search_selection, NULL, &sel_iter)) - { - /* Get item to delete */ - gint selected_item_nr; - gtk_tree_model_get((GtkTreeModel*)search_list, &sel_iter, 0, &selected_item_nr, -1); - GSList* element = g_slist_nth(history, selected_item_nr); - /* Remove entry */ - history = g_slist_remove(history, element->data); - search_history(); + gint selected_count = gtk_tree_selection_count_selected_rows(search_selection); + if (selected_count > 0) { + GtkListStore *store; + GArray *sel; + gint i; + store = GTK_LIST_STORE(gtk_tree_view_get_model((GtkTreeView*)treeview_search)); + sel = g_array_new(FALSE, FALSE, sizeof(GtkTreeIter)); + gtk_tree_selection_selected_foreach(search_selection, add_iter, sel); + gtk_tree_selection_unselect_all(search_selection); + for (i = 0; i < sel->len; i++) { + GtkTreeIter *iter = &g_array_index(sel, GtkTreeIter, i); + gtk_list_store_remove(store, iter); + } + g_array_free(sel, TRUE); } } @@ -257,11 +272,14 @@ static gint search_click(GtkWidget *widget, GdkEventButton *event, GtkWidget *se return FALSE; } -static gint search_key_pressed(GtkWidget *widget, GdkEventKey *event, gpointer user_data) +static gint search_key_released(GtkWidget *widget, GdkEventKey *event, gpointer user_data) +{ + search_history(); + return FALSE; +} + +static gboolean treeview_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; } @@ -301,7 +319,7 @@ gboolean show_search() 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); + g_signal_connect((GObject*)search_entry, "key-release-event", (GCallback)search_key_released, NULL); /* Build the exclude treeview */ GtkWidget* scrolled_window_search = gtk_scrolled_window_new( @@ -336,8 +354,9 @@ gboolean show_search() g_signal_connect((GObject*)close_button, "clicked", (GCallback)search_history, NULL); GtkTreeSelection* search_selection = gtk_tree_view_get_selection((GtkTreeView*)treeview_search); - gtk_tree_selection_set_mode(search_selection, GTK_SELECTION_BROWSE); + gtk_tree_selection_set_mode(search_selection, GTK_SELECTION_MULTIPLE); g_signal_connect((GObject*)treeview_search, "button_press_event", (GCallback)search_click, search_dialog); + g_signal_connect((GObject*)treeview_search, "key-press-event", (GCallback)treeview_key_pressed, NULL); g_signal_connect((GtkDialog*)search_dialog, "response", (GCallback)search_window_response, search_dialog); gtk_widget_show_all(vbox_search);