@@ -19,11 +19,12 @@ using namespace std;
19
19
#include " edbee/texteditorwidget.h"
20
20
#include " edbee/views/textrenderer.h"
21
21
#include " edbee/views/texttheme.h"
22
+ #include " edbee/models/texteditorconfig.h"
22
23
// #include "diff_match_patch.h"
23
24
24
25
typedef diff_match_patch<string> stringdiff;
25
26
26
- string getFileContents (const char * path)
27
+ string getFileContents (string path)
27
28
{
28
29
ifstream myfile (path);
29
30
if (myfile.is_open ())
@@ -34,7 +35,7 @@ string getFileContents(const char* path)
34
35
// TODO: who deallocates buffer and myfile?
35
36
return buffer.str ();
36
37
}
37
- else qDebug () << " Unable to open file" << path;
38
+ else qDebug () << " Unable to open file" << path. c_str () ;
38
39
return NULL ;
39
40
}
40
41
@@ -86,29 +87,6 @@ QVector<QVector<stringdiff::Diff>> createDiffLookup(list<stringdiff::Diff> diffs
86
87
}
87
88
88
89
}
89
-
90
- // for (int lineOffset = 0; lineOffset < lineCount; ++lineOffset) {
91
- // int currentLine = lineNumber + lineOffset;
92
-
93
- // qDebug() << "Trying line" << currentLine;
94
- // stringdiff::Diff diff = *it;
95
- // diffsPerLine[currentLine].append(diff);
96
- // qDebug() << "appended" << diff.operation;
97
- // QVector<stringdiff::Diff*> diffsAtLine = diffsPerLine.at(currentLine);
98
- // diffsAtLine.append(diff);
99
- // qDebug() << diffsAtLine;
100
- //
101
- // dereference and grab address of iterator.
102
-
103
-
104
- // // auto diffsAtLine = diffsPerLine->at(currentLine
105
- //
106
- // // int currentLine = lineNumber + lineOffset;
107
- // // if (diffsPerLine[currentLine] == NULL) { diffsPerLine[currentLine]
108
- // qDebug() << "Line " << lineNumber + lineOffset << " change " << it->operation;
109
- // }
110
- // lineNumber += lineCount;
111
- // }
112
90
}
113
91
114
92
return diffsPerLine;
@@ -122,35 +100,23 @@ bool fileExists(QString path) {
122
100
}
123
101
124
102
125
- // / This is an example that shows how to load a grammar file and a theme file
126
- // / manually and initialise the editor with it
127
103
int main (int argc, char *argv[])
128
104
{
129
105
QApplication a (argc, argv);
130
106
107
+ QString appDataPath_;
108
+ #ifdef Q_OS_MAC
109
+ appDataPath_ = applicationDirPath () + " /../Resources/" ;
110
+ #else
111
+ appDataPath_ = qApp->applicationDirPath () + " /data/" ;
112
+ #endif
113
+
131
114
// initialize edbee
132
115
edbee::Edbee* edbee = edbee::Edbee::instance ();
116
+ edbee->setKeyMapPath (QString (" %1%2" ).arg (appDataPath_).arg (" keymaps" ));
117
+ edbee->setGrammarPath (QString (" %1%2" ).arg (appDataPath_).arg (" syntaxfiles" ));
118
+ edbee->setThemePath (QString (" %1%2" ).arg (appDataPath_).arg (" themes" ));
133
119
edbee->autoInit ();
134
-
135
- // TODO: Check the edbee app for a proper way to detect grammars and themes.
136
-
137
- // read the grammar file
138
- edbee::TextGrammarManager* grammarManager = edbee->grammarManager ();
139
- edbee::TextGrammar* grammar = grammarManager->readGrammarFile ( " HTML.tmLanguage" );
140
- if ( !grammar ) {
141
- qDebug () << " Grammar couldn't be loaded: " << grammarManager->lastErrorMessage ();
142
- edbee->shutdown (); // call this method manuall to prevent memory leak warnings. When the exec method is called this isn't required
143
- return 1 ;
144
- }
145
-
146
- // read the theme file
147
- edbee::TextThemeManager* themeManager = edbee->themeManager ();
148
- edbee::TextTheme* theme = themeManager->readThemeFile ( " Solarized (Dark).tmTheme" );
149
- if ( !theme) {
150
- qDebug () << " Theme couldn't be loaded: " << themeManager->lastErrorMessage ();
151
- edbee->shutdown (); // call this method manuall to prevent memory leak warnings. When the exec method is called this isn't required
152
- return 1 ;
153
- }
154
120
155
121
// string leftContent = "<html>\n\t<title>Yo</title>\n\t<body>\n\t\t<h1>Hello Left</h1>\n\t</body>\n</html>\n";
156
122
// string rightContent = "<html>\n\t<body>\n\t\t<h1>Hello Right</h1>\n\t</body>\n\t<footer>fin</footer>\n</html>\n";
@@ -161,54 +127,31 @@ int main(int argc, char *argv[])
161
127
string leftContent = " Mary had a little lamb,\n whose fleece was white as snow.\n\n " ;
162
128
string rightContent = " Mary had a little lamb,\n whose fleece was red as snow.\n\n And everywhere that Mary went,\n the lamb was sure to go.\n " ;
163
129
164
- // //
165
- // string leftContent = "asdf\nyo";
166
- // string rightContent = "asdf\nbe";
167
-
168
- // if (argc > 2) {
169
- //
170
- // char* file1 = argv[1];
171
- // char* file2 = argv[2];
172
- //
173
- // if (fileExists(file1)) {
174
- // leftContent = getFileContents(file1);
175
- // }
176
- //
177
- // if (fileExists(file2)) {
178
- // rightContent = getFileContents(file2);
179
- // }
180
- //
181
- // }
130
+ string leftFile = " left.txt" ;
131
+ string rightFile = " right.txt" ;
132
+
133
+ if (argc > 2 ) {
134
+
135
+ leftFile = argv[0 ];
136
+ rightFile = argv[1 ];
137
+
138
+ if (fileExists (QString::fromStdString (leftFile))) {
139
+ leftContent = getFileContents (leftFile);
140
+ }
141
+
142
+ if (fileExists (QString::fromStdString (rightFile))) {
143
+ rightContent = getFileContents (rightFile);
144
+ }
145
+
146
+ }
182
147
183
- // get the minimal diff
184
148
diff_match_patch<string> dmp;
185
149
auto diffs = dmp.diff_lines (leftContent, rightContent);
186
-
187
150
auto deletionLookup = createDiffLookup (diffs, stringdiff::DELETE);
188
- summarizeLines (deletionLookup);
189
-
190
-
191
151
auto insertLookup = createDiffLookup (diffs, stringdiff::INSERT);
192
- summarizeLines (insertLookup);
193
- //
194
- // auto deletions = findDiffsByLine(diffs, stringdiff::DELETE);
195
- // auto insertions = findDiffsByLine(diffs, stringdiff::INSERT);
196
-
197
- // for (int i = 0; i < deletions.size(); ++i) {
198
- // qDebug() << deletions[i] << " ";
199
- // }
200
- //
201
152
202
- // TODO: generate a diff object to be used by both.
203
- /*
204
-
205
- Options:
206
-
207
- Set a unified diff to both sides, with left interpreting differently from right.
208
- * left: '-' means red
209
- * right: '+' means green
210
- * both: '-' followed by '+' means change
211
-
153
+ /*
154
+
212
155
We need support for:
213
156
214
157
* Shading of line number columns?
@@ -217,20 +160,21 @@ int main(int argc, char *argv[])
217
160
218
161
*/
219
162
163
+ QFont font = QFont (" Consolas" , 12 );
220
164
// TODO: read only?
221
165
edbee::TextEditorWidget left;
222
- left.textDocument ()->setLanguageGrammar ( grammar );
223
- left.textRenderer ()->setTheme ( theme );
166
+ left.config ()->setFont (font);
167
+ left.config ()->setThemeName (" Oceanic Next" );
168
+ left.textDocument ()->setLanguageGrammar (edbee::Edbee::instance ()->grammarManager ()->detectGrammarWithFilename (QString::fromStdString (leftFile)));
224
169
left.textDocument ()->setDiffLookup (deletionLookup);
225
170
left.textDocument ()->setText (QString::fromStdString (leftContent));
226
- // left.textDocument()->setDiffStatus(&deletions);
227
-
171
+
228
172
edbee::TextEditorWidget right;
229
- right.textDocument ()->setLanguageGrammar ( grammar );
230
- right.textRenderer ()->setTheme ( theme );
173
+ right.config ()->setFont (font);
174
+ right.config ()->setThemeName (" Oceanic Next" );
175
+ right.textDocument ()->setLanguageGrammar (edbee::Edbee::instance ()->grammarManager ()->detectGrammarWithFilename (QString::fromStdString (rightFile)));
231
176
right.textDocument ()->setDiffLookup (insertLookup);
232
177
right.textDocument ()->setText (QString::fromStdString (rightContent));
233
- // right.textDocument()->setDiffStatus(&insertions);
234
178
235
179
QSplitter *splitter = new QSplitter ();
236
180
splitter->addWidget (&left);
0 commit comments