Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
-Added support for compare preferences
  • Loading branch information
readgs committed Sep 10, 2003
1 parent f89c429 commit 3810ac8
Show file tree
Hide file tree
Showing 10 changed files with 165 additions and 17 deletions.
19 changes: 15 additions & 4 deletions Application.cpp
Expand Up @@ -193,11 +193,22 @@ void Application::CmdRecompare()
GetWindowAsCompareUI(Browser->GetActiveWindow())->Recompare();
}

void Application::CmdPreferences()
void Application::CmdIgnoreWhitespace(bool Value)
{
// TODO - Eventually we'll pass a real config object here
ConfigUI MyConfigUI(NULL);
MyConfigUI.ShowModal();
Debug("Ignore Whitespace = %d", Value);
Config::SetIgnoreWhitespace(Value);
}

void Application::CmdIgnoreLineEndings(bool Value)
{
Debug("Ignore Line Endings = %d", Value);
Config::SetIgnoreLineEndings(Value);
}

void Application::CmdIgnoreCase(bool Value)
{
Debug("Ignore Case = %d", Value);
Config::SetIgnoreCase(Value);
}

void Application::CmdToolbar()
Expand Down
5 changes: 4 additions & 1 deletion Application.h
Expand Up @@ -69,7 +69,10 @@ namespace MojoMerge
static void CmdPaste();
static void CmdSelectAll();
static void CmdRecompare();
static void CmdPreferences();
//static void CmdPreferences();
static void CmdIgnoreWhitespace(bool Value);
static void CmdIgnoreLineEndings(bool Value);
static void CmdIgnoreCase(bool Value);
static void CmdToolbar();
static void CmdStatusbar();
static void CmdExit();
Expand Down
10 changes: 8 additions & 2 deletions CompareFilesUI.cpp
Expand Up @@ -332,6 +332,12 @@ void CompareFilesUI::Recompare()
{
Hunk *FirstHunk;
int i;
int MyDiffOptions = 0;

// Set our diffing options based on the Config object
MyDiffOptions |= Config::GetIgnoreCase()?DiffOption_IgnoreCase:0;
MyDiffOptions |= Config::GetIgnoreWhitespace()?DiffOption_IgnoreWhitespace:0;
MyDiffOptions |= Config::GetIgnoreLineEndings()?DiffOption_IgnoreLineEnding:0;

// Get buffers from both file panels
wxString Buffer1 = FilePanels[DiffFile_One]->GetBuffer();
Expand All @@ -351,7 +357,7 @@ void CompareFilesUI::Recompare()
wxString Buffer3 = FilePanels[DiffFile_Three]->GetBuffer();

// Perform three-way comparison
FirstHunk = MyDiff->CompareFiles(DiffOption_None,
FirstHunk = MyDiff->CompareFiles((DiffOptions)MyDiffOptions,
Buffer1.GetData(),
Buffer2.GetData(),
Buffer3.GetData());
Expand All @@ -367,7 +373,7 @@ void CompareFilesUI::Recompare()
// If two-way comparison
else
{
FirstHunk = MyDiff->CompareFiles(DiffOption_None,
FirstHunk = MyDiff->CompareFiles((DiffOptions)MyDiffOptions,
Buffer1.GetData(),
Buffer2.GetData());
// Only create Merge object if there are diffs
Expand Down
63 changes: 63 additions & 0 deletions Config.cpp
Expand Up @@ -181,3 +181,66 @@ void Config::SetDiff3Path(wxString &Value)
// Fails if write was not successful
assert(i);
}

void Config::SetIgnoreWhitespace(bool Value)
{
// MyConfigData can't be NULL
assert(MyConfigData);
bool i = MyConfigData->Write(wxT("IgnoreWhitespace"), Value);
// Fails if write was not successful
assert(i);
}

void Config::SetIgnoreLineEndings(bool Value)
{
// MyConfigData can't be NULL
assert(MyConfigData);
bool i = MyConfigData->Write(wxT("IgnoreLineEndings"), Value);
// Fails if write was not successful
assert(i);
}

void Config::SetIgnoreCase(bool Value)
{
// MyConfigData can't be NULL
assert(MyConfigData);
bool i = MyConfigData->Write(wxT("IgnoreCase"), Value);
// Fails if write was not successful
assert(i);
}

bool Config::GetIgnoreWhitespace()
{
// Return value
bool Value;

// MyConfigData can't be NULL
assert(MyConfigData);
MyConfigData->Read(wxT("IgnoreWhitespace"), &Value, false);

return Value;
}

bool Config::GetIgnoreLineEndings()
{
// Return value
bool Value;

// MyConfigData can't be NULL
assert(MyConfigData);
MyConfigData->Read(wxT("IgnoreLineEndings"), &Value, false);

return Value;
}

bool Config::GetIgnoreCase()
{
// Return value
bool Value;

// MyConfigData can't be NULL
assert(MyConfigData);
MyConfigData->Read(wxT("IgnoreCase"), &Value, false);

return Value;
}
7 changes: 7 additions & 0 deletions Config.h
Expand Up @@ -148,6 +148,13 @@ namespace MojoMerge
* none
*/
static void SetDiff3Path(wxString &Value);

static void SetIgnoreWhitespace(bool Value);
static void SetIgnoreLineEndings(bool Value);
static void SetIgnoreCase(bool Value);
static bool GetIgnoreWhitespace();
static bool GetIgnoreLineEndings();
static bool GetIgnoreCase();
private:
static wxConfig *MyConfigData;
};
Expand Down
37 changes: 35 additions & 2 deletions GNUDiff.cpp
Expand Up @@ -15,13 +15,17 @@
#include <assert.h>
#include <string.h>
#include "GNUDiff.h"
#include "Application.h"

#ifdef WIN32
#define mktemp _mktemp
#define unlink _unlink
#define popen _popen
#endif

#define DIFFOPTION_IGNOREWHITESPACE " -w "
#define DIFFOPTION_IGNORECASE " -i "

using namespace MojoMerge;

GNUDiff::GNUDiff(const char *DiffPath, const char *Diff3Path,
Expand Down Expand Up @@ -155,6 +159,7 @@ void GNUDiff::GetDiffOutput(const char *Path, const char *CommandLine)
DiffResult = new char[DIFF_RESULT_BUFFER_SIZE];
// Memory allocation error
assert(DiffResult);
Application::Debug("Running '%s'", FullCommandLine);
// Run the diff program
Pipe = popen(FullCommandLine, "r");
// Pipe can't be NULL
Expand Down Expand Up @@ -184,7 +189,17 @@ Hunk *GNUDiff::RunDiff(DiffOptions Options, const char *File1,
// Combination of file name length plus space can't be too big
assert(strlen(File1) + strlen(File2) + 1 < MOJO_MAX_PATH - 1);

strcpy(CommandLine, File1);
// Start with a blank commandline
strcpy(CommandLine, "");

// Append any commandline options as necessary
if(Options & DiffOption_IgnoreCase)
strcat(CommandLine, DIFFOPTION_IGNORECASE);
if(Options & DiffOption_IgnoreWhitespace)
strcat(CommandLine, DIFFOPTION_IGNOREWHITESPACE);

// Append files to compare at the end of the commandline
strcat(CommandLine, File1);
strcat(CommandLine, " ");
strcat(CommandLine, File2);

Expand All @@ -199,6 +214,8 @@ Hunk *GNUDiff::RunDiff3(DiffOptions Options, const char *File1,
{
// Commandline we pass to the 'diff3' program
char CommandLine[MOJO_MAX_PATH];
// Special arguments we'll pass to Diff2
char Diff2CommandLine[MOJO_MAX_PATH];

// Files can't be NULL
assert(File1);
Expand All @@ -212,12 +229,28 @@ Hunk *GNUDiff::RunDiff3(DiffOptions Options, const char *File1,
assert(strlen(File1) + strlen(File2) + strlen(File3) + 2 <
MOJO_MAX_PATH - 1);

strcpy(CommandLine, File1);
strcpy(CommandLine, "--diff-program=./diff.sh ");
strcat(CommandLine, File1);
strcat(CommandLine, " ");
strcat(CommandLine, File2);
strcat(CommandLine, " ");
strcat(CommandLine, File3);

//***This creates a special file that the diff2.sh script uses to pass args
//***to diff.
// Start with a blank commandline
strcpy(Diff2CommandLine, "");
// Append any commandline options as necessary
if(Options & DiffOption_IgnoreCase)
strcat(Diff2CommandLine, DIFFOPTION_IGNORECASE);
if(Options & DiffOption_IgnoreWhitespace)
strcat(Diff2CommandLine, DIFFOPTION_IGNOREWHITESPACE);
FILE *DiffOptionsStream = fopen("diffoptions", "wt");
assert(DiffOptionsStream);
fprintf(DiffOptionsStream, "%s", Diff2CommandLine);
fflush(DiffOptionsStream);
fclose(DiffOptionsStream);

// TODO - Options are not supported by 'diff3'
GetDiffOutput(Diff3Path, CommandLine);
// Parse the output and return any hunks found
Expand Down
5 changes: 4 additions & 1 deletion Identifiers.h
Expand Up @@ -67,7 +67,10 @@ enum
ID_SELECTALL_MENU,
//ID_COMPARE_MENU,
ID_RECOMPARE_MENU,
ID_PREFERENCES_MENU,
ID_IGNORE_WHITESPACE_MENU,
ID_IGNORE_LINE_ENDINGS_MENU,
ID_IGNORE_CASE_MENU,
//ID_PREFERENCES_MENU,
ID_VIEW_MENU,
ID_TOOLBAR_MENU,
ID_STATUSBAR_MENU,
Expand Down
19 changes: 16 additions & 3 deletions MainWindow.cpp
Expand Up @@ -148,9 +148,19 @@ void MainWindow::OnRecompare(wxCommandEvent& event)
Application::CmdRecompare();
}

void MainWindow::OnPreferences(wxCommandEvent& event)
void MainWindow::OnIgnoreLineEndings(wxCommandEvent& event)
{
Application::CmdPreferences();
Application::CmdIgnoreLineEndings(MyMenu->IsChecked(ID_IGNORE_LINE_ENDINGS_MENU));
}

void MainWindow::OnIgnoreCase(wxCommandEvent& event)
{
Application::CmdIgnoreCase(MyMenu->IsChecked(ID_IGNORE_CASE_MENU));
}

void MainWindow::OnIgnoreWhitespace(wxCommandEvent& event)
{
Application::CmdIgnoreWhitespace(MyMenu->IsChecked(ID_IGNORE_WHITESPACE_MENU));
}

void MainWindow::OnToolbar(wxCommandEvent& event)
Expand Down Expand Up @@ -251,7 +261,10 @@ BEGIN_EVENT_TABLE(MainWindow, wxFrame)
EVT_MENU(ID_PASTE_MENU, MainWindow::OnPaste)
EVT_MENU(ID_SELECTALL_MENU, MainWindow::OnSelectAll)
EVT_MENU(ID_RECOMPARE_MENU, MainWindow::OnRecompare)
EVT_MENU(ID_PREFERENCES_MENU, MainWindow::OnPreferences)
//EVT_MENU(ID_PREFERENCES_MENU, MainWindow::OnPreferences)
EVT_MENU(ID_IGNORE_WHITESPACE_MENU, MainWindow::OnIgnoreWhitespace)
EVT_MENU(ID_IGNORE_LINE_ENDINGS_MENU, MainWindow::OnIgnoreLineEndings)
EVT_MENU(ID_IGNORE_CASE_MENU, MainWindow::OnIgnoreCase)
EVT_MENU(ID_TOOLBAR_MENU, MainWindow::OnToolbar)
EVT_MENU(ID_STATUSBAR_MENU, MainWindow::OnStatusbar)
// Toolbar menu events
Expand Down
5 changes: 4 additions & 1 deletion MainWindow.h
Expand Up @@ -77,7 +77,10 @@ namespace MojoMerge
void OnPaste(wxCommandEvent& event);
void OnSelectAll(wxCommandEvent& event);
void OnRecompare(wxCommandEvent& event);
void OnPreferences(wxCommandEvent& event);
//void OnPreferences(wxCommandEvent& event);
void OnIgnoreWhitespace(wxCommandEvent& event);
void OnIgnoreLineEndings(wxCommandEvent& event);
void OnIgnoreCase(wxCommandEvent& event);
void OnToolbar(wxCommandEvent& event);
void OnStatusbar(wxCommandEvent& event);
void OnCheckMail(wxCommandEvent& event);
Expand Down
12 changes: 9 additions & 3 deletions Menu.cpp
Expand Up @@ -5,6 +5,7 @@
#include "Menu.h"
#include "Identifiers.h"
#include "Application.h"
#include "Config.h"

using namespace MojoMerge;

Expand Down Expand Up @@ -51,10 +52,15 @@ Menu::Menu()
CompareMenu->Append(ID_RECOMPARE_MENU, wxT("Recompare\tF5"), wxT(""));
CompareMenu->AppendSeparator();
//CompareMenu->Append(ID_PREFERENCES_MENU, wxT("Preferences"), wxT(""));
CompareMenu->Append(ID_PREFERENCES_MENU, wxT("Ignore white-space"), wxT(""));
CompareMenu->Append(ID_PREFERENCES_MENU, wxT("Ignore line ending diffs"), wxT(""));
CompareMenu->Append(ID_IGNORE_WHITESPACE_MENU, wxT("Ignore white-space"), wxT(""), true);
CompareMenu->Append(ID_IGNORE_CASE_MENU, wxT("Ignore case"), wxT(""), true);
//CompareMenu->Append(ID_IGNORE_LINE_ENDINGS_MENU, wxT("Ignore line ending diffs"), wxT(""), true);
Append(CompareMenu, wxT("Compare"));

// Set menu items based on config object
Check(ID_IGNORE_WHITESPACE_MENU, Config::GetIgnoreWhitespace());
Check(ID_IGNORE_CASE_MENU, Config::GetIgnoreCase());
//Check(ID_IGNORE_LINE_ENDINGS_MENU, Config::GetIgnoreLineEndings());

// Create "View" menu
//wxMenu *ViewMenu = new wxMenu();
//ViewMenu->Append(ID_TOOLBAR_MENU, wxT("Toolbar"), wxT(""), TRUE);
Expand Down

0 comments on commit 3810ac8

Please sign in to comment.