Author: mike
Date: 2012-02-07 23:59:53 -0800 (Tue, 07 Feb 2012)
New Revision: 455
Log:
Fix reload and next/prev change.
Fix system menu bar usage.
Modified:
trunk/fldiff/DiffView.cxx
trunk/fldiff/DiffView.h
trunk/fldiff/DiffWindow.cxx
trunk/fldiff/DiffWindow.h
Modified: trunk/fldiff/DiffView.cxx
===================================================================
--- trunk/fldiff/DiffView.cxx 2012-02-06 18:02:20 UTC (rev 454)
+++ trunk/fldiff/DiffView.cxx 2012-02-08 07:59:53 UTC (rev 455)
@@ -3,7 +3,7 @@
//
// DiffView widget code.
//
-// Copyright 2005-2006 by Michael Sweet.
+// Copyright 2005-2012 by Michael Sweet.
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License v2 as published
@@ -44,7 +44,15 @@
#include "PtProcess.h"
+
//
+// Local functions...
+//
+
+static bool has_subdirectory(const char *path, const char *name, bool
recurse = true);
+
+
+//
// Width/height of scrollbars...
//
@@ -950,7 +958,7 @@
snprintf(line, sizeof(line), "%s/CVS", file1);
- if (!access(line, 0))
+ if (has_subdirectory(file1, "CVS", 0))
{
if (file2)
snprintf(command, sizeof(command), "cvs diff -r \"%s\" -u \"%s\"",
@@ -959,21 +967,24 @@
snprintf(command, sizeof(command), "cvs diff -u \"%s\"",
file1);
}
- else
+ else if (has_subdirectory(file1, ".git"))
{
- snprintf(line, sizeof(line), "%s/.svn", file1);
-
- if (!access(line, 0))
- {
- if (file2)
- snprintf(command, sizeof(command), "svn diff -N -r \"%s\" \"%s\"",
- file2 + 1, file1);
- else
- snprintf(command, sizeof(command), "svn diff -N \"%s\"", file1);
- }
+ if (file2)
+ snprintf(command, sizeof(command), "git diff -N -r \"%s\" \"%s\"",
+ file2 + 1, file1);
else
- return (false);
+ snprintf(command, sizeof(command), "git diff -N \"%s\"", file1);
}
+ else if (has_subdirectory(file1, ".svn"))
+ {
+ if (file2)
+ snprintf(command, sizeof(command), "svn diff -N -r \"%s\" \"%s\"",
+ file2 + 1, file1);
+ else
+ snprintf(command, sizeof(command), "svn diff -N \"%s\"", file1);
+ }
+ else
+ return (false);
}
else
{
@@ -981,13 +992,14 @@
line[sizeof(line) - 1] = '\0';
if ((ptr = strrchr(line, '/')) != NULL)
- ptr ++;
+ *ptr = '\0';
else
- ptr = line;
+ {
+ line[0] = '.';
+ line[1] = '\0';
+ }
- strncpy(ptr, "CVS", sizeof(line) - 1 - (ptr - line));
-
- if (!access(line, 0))
+ if (has_subdirectory(line, "CVS", 0))
{
if (file2)
snprintf(command, sizeof(command), "cvs -q diff -r \"%s\" -u \"%s\"",
@@ -995,24 +1007,30 @@
else
snprintf(command, sizeof(command), "cvs -q diff -u \"%s\"", file1);
}
- else
+ else if (has_subdirectory(line, ".git"))
{
- strncpy(ptr, ".svn", sizeof(line) - 1 - (ptr - line));
+ const char *diffopt = ignoreblanks() ? "-bw'" : "";
- if (!access(line, 0))
- {
- const char *diffopt = ignoreblanks() ?
- "--diff-cmd diff --extensions '-bBwEu'" : "";
- if (file2)
- snprintf(command, sizeof(command), "svn diff %s -r \"%s\" \"%s\"",
- diffopt, file2 + 1, file1);
- else
- snprintf(command, sizeof(command), "svn diff %s \"%s\"",
- diffopt, file1);
- }
+ if (file2)
+ snprintf(command, sizeof(command), "git diff %s -r \"%s\" \"%s\"",
+ diffopt, file2 + 1, file1);
else
- return (false);
+ snprintf(command, sizeof(command), "git diff %s \"%s\"",
+ diffopt, file1);
}
+ else if (has_subdirectory(line, ".svn"))
+ {
+ const char *diffopt = ignoreblanks() ?
+ "--diff-cmd diff --extensions '-bBwEu'" : "";
+ if (file2)
+ snprintf(command, sizeof(command), "svn diff %s -r \"%s\" \"%s\"",
+ diffopt, file2 + 1, file1);
+ else
+ snprintf(command, sizeof(command), "svn diff %s \"%s\"",
+ diffopt, file1);
+ }
+ else
+ return (false);
}
if (!pdiff.popen(command))
@@ -1488,13 +1506,15 @@
//
void
-DiffView::showline(int l) // I - Line to show
+DiffView::showline(int l, // I - Line to show
+ bool at_top) // I - Show line at top of
window
{
l *= textsize_;
if (l < topline_ || l >= (topline_ + h() - SCROLLER))
{
- l -= (h() - SCROLLER) / 2;
+ if (!at_top)
+ l -= (h() - SCROLLER) / 2;
if (l < 0)
l = 0;
@@ -1542,5 +1562,46 @@
//
+// 'has_subdirectory()' - Determine whether the given path contains the named
+// subdirectory.
+//
+
+static bool // O - True if subdirectory exists,
false otherwise
+has_subdirectory(const char *path, // I - Base path
+ const char *name, // I - Name to look for
+ bool recurse) // I - True to recurse into parent dirs
+{
+ char filename[1024], // Full name
+ *ptr; // Pointer into name
+
+
+ if (*path)
+ snprintf(filename, sizeof(filename), "%s/%s", path, name);
+ else
+ {
+ strncpy(filename, name, sizeof(filename) - 1);
+ filename[sizeof(filename) - 1] = '\0';
+ }
+
+// printf("has_subdirectory(path=\"%s\", name=\"%s\", recurse=%s)
filename=\"%s\"\n", path, name,
+// recurse ? "true" : "false", filename);
+
+ if (fl_filename_isdir(filename))
+ return (true);
+ else if (!recurse)
+ return (false);
+
+ fl_filename_absolute(filename, sizeof(filename), *path ? path : ".");
+ if ((ptr = strrchr(filename, '/')) != NULL && ptr > filename)
+ {
+ *ptr = '\0';
+ return (has_subdirectory(filename, name));
+ }
+ else
+ return (false);
+}
+
+
+//
// End of "$Id$".
//
Modified: trunk/fldiff/DiffView.h
===================================================================
--- trunk/fldiff/DiffView.h 2012-02-06 18:02:20 UTC (rev 454)
+++ trunk/fldiff/DiffView.h 2012-02-08 07:59:53 UTC (rev 455)
@@ -103,7 +103,7 @@
int select_start() const { return (select_start_); }
char *selection();
int selection_length();
- void showline(int l);
+ void showline(int l, bool at_top = false);
void showlinenum(bool b) { showlinenum_ = b; redraw(); }
bool showlinenum() const { return (showlinenum_); }
void ignoreblanks(bool b) { ignoreblanks_ = b; }
Modified: trunk/fldiff/DiffWindow.cxx
===================================================================
--- trunk/fldiff/DiffWindow.cxx 2012-02-06 18:02:20 UTC (rev 454)
+++ trunk/fldiff/DiffWindow.cxx 2012-02-08 07:59:53 UTC (rev 455)
@@ -129,11 +129,11 @@
// I - Second file
: Fl_Overlay_Window(640, 480),
menubar_(0, 0, 640, 25),
-//#ifdef __APPLE__
-// view_(0, 0, 640, 480)
-//#else
+#ifdef __APPLE__
+ view_(0, 0, 640, 480)
+#else
view_(0, 25, 640, 455)
-//#endif /* __APPLE__ */
+#endif /* __APPLE__ */
{
int W, // Width of window
H; // Height of window
@@ -201,6 +201,12 @@
prefs_.get("window_width", W, 640);
prefs_.get("window_height", H, 480);
+ if (W > Fl::w())
+ W = Fl::w();
+
+ if (H > Fl::h())
+ H = Fl::h();
+
resize(x(), y(), W, H);
// Clear the zoom data...
@@ -281,10 +287,7 @@
DiffWindow::close_cb(Fl_Menu_Bar *m, // I - Menubar
DiffWindow *dw) // I - Window
{
- if (dw->next_ || first_ != dw)
- Fl::delete_widget(dw);
- else
- dw->load(NULL, NULL);
+ Fl::delete_widget(dw);
}
@@ -706,6 +709,18 @@
switch (event)
{
+ case FL_SHORTCUT :
+ switch (Fl::event_key())
+ {
+ case 'n' :
+ next_change_cb(NULL, this);
+ break;
+
+ case 'p' :
+ prev_change_cb(NULL, this);
+ break;
+ }
+
case FL_PUSH :
if (zoom_pos_ >= 0)
{
@@ -1129,7 +1144,7 @@
{
int topline = dw->view_.topline();
dw->view_.load(dw->file1_, dw->file2_);
- dw->view_.showline(topline);
+ dw->view_.showline(topline, true);
}
Modified: trunk/fldiff/DiffWindow.h
===================================================================
--- trunk/fldiff/DiffWindow.h 2012-02-06 18:02:20 UTC (rev 454)
+++ trunk/fldiff/DiffWindow.h 2012-02-08 07:59:53 UTC (rev 455)
@@ -30,7 +30,7 @@
class DiffWindow : public Fl_Overlay_Window
{
- Fl_Menu_Bar menubar_; // Menubar
+ Fl_Sys_Menu_Bar menubar_; // Menubar
DiffView view_; // Diff viewing widget
const char *file1_, // First file
*file2_; // Second file
_______________________________________________
fltk-commit mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-commit