[gnome-commander] advrename: fix for auto width calculation (step>1)
- From: Piotr Eljasiak <epiotr src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-commander] advrename: fix for auto width calculation (step>1)
- Date: Thu, 8 Dec 2011 20:48:07 +0000 (UTC)
commit d0a99c62971f61f47d65887a7e8f91553ff0e404
Author: Piotr Eljasiak <epiotr src gnome org>
Date: Thu Dec 8 21:47:55 2011 +0100
advrename: fix for auto width calculation (step>1)
src/dialogs/gnome-cmd-advrename-dialog.cc | 7 ++-----
src/gnome-cmd-advrename-lexer.h | 2 +-
src/gnome-cmd-advrename-lexer.ll | 10 ++++++++--
3 files changed, 11 insertions(+), 8 deletions(-)
---
diff --git a/src/dialogs/gnome-cmd-advrename-dialog.cc b/src/dialogs/gnome-cmd-advrename-dialog.cc
index a444795..ab5ee37 100644
--- a/src/dialogs/gnome-cmd-advrename-dialog.cc
+++ b/src/dialogs/gnome-cmd-advrename-dialog.cc
@@ -20,7 +20,6 @@
#include <config.h>
#include <sys/types.h>
-#include <math.h>
#include <regex.h>
#include <unistd.h>
#include <errno.h>
@@ -619,11 +618,9 @@ inline GtkWidget *create_files_view ()
void GnomeCmdAdvrenameDialog::update_new_filenames()
{
- gint n = gtk_tree_model_iter_n_children (files, NULL);
-
- gnome_cmd_advrename_reset_counter (defaults.default_profile.counter_start,
+ gnome_cmd_advrename_reset_counter (gtk_tree_model_iter_n_children (files, NULL),
+ defaults.default_profile.counter_start,
defaults.default_profile.counter_width,
- n ? log10(n)+1 : 1,
defaults.default_profile.counter_step);
GtkTreeIter i;
diff --git a/src/gnome-cmd-advrename-lexer.h b/src/gnome-cmd-advrename-lexer.h
index c220fd4..6eb0344 100644
--- a/src/gnome-cmd-advrename-lexer.h
+++ b/src/gnome-cmd-advrename-lexer.h
@@ -27,7 +27,7 @@
#define NAME_MAX (FILENAME_MAX)
#endif
-void gnome_cmd_advrename_reset_counter(long start=1, int precision=-1, int auto_precision=1, int step=1);
+void gnome_cmd_advrename_reset_counter(int n, long start=1, int precision=-1, int step=1);
void gnome_cmd_advrename_parse_template(const char *template_string, gboolean &has_counters);
char *gnome_cmd_advrename_gen_fname(GnomeCmdFile *f, size_t new_fname_size=NAME_MAX);
diff --git a/src/gnome-cmd-advrename-lexer.ll b/src/gnome-cmd-advrename-lexer.ll
index cd6410c..f7ef8ec 100644
--- a/src/gnome-cmd-advrename-lexer.ll
+++ b/src/gnome-cmd-advrename-lexer.ll
@@ -29,10 +29,11 @@
#include <stdlib.h>
#include <string.h>
#include <time.h>
+#include <math.h>
#include <string>
#include <vector>
-
+#include <algorithm>
#include "gnome-cmd-includes.h"
#include "gnome-cmd-file.h"
@@ -312,9 +313,14 @@ tag_name {ape}|{audio}|{doc}|{exif}|{file}|{flac}|{id3}|{image}|{iptc}|{pdf}|
%%
-void gnome_cmd_advrename_reset_counter(long start, int precision, int auto_precision, int step)
+void gnome_cmd_advrename_reset_counter(int n, long start, int precision, int step)
{
+ n = std::max(abs(start),abs(--n*step+start));
+
+ int auto_precision = n ? log10(n)+1 : 1;
+
auto_precision = CLAMP(auto_precision,1,MAX_PRECISION);
+
if (!precision)
precision = auto_precision;
else
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]