Skip to content

Commit 464ff79

Browse files
authored
Updated Quick Note code
New feature: Quick Note should be more stable and better to view / edit
1 parent 4e0b6e1 commit 464ff79

File tree

3 files changed

+118
-39
lines changed

3 files changed

+118
-39
lines changed

src/app.cxx

Lines changed: 99 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -40,31 +40,6 @@
4040
*/
4141
int SVInput::handle (int evt)
4242
{
43-
// save and close the quicknote editor
44-
if (evt == FL_KEYUP && app->quickNoteWindow != 0)
45-
{
46-
if (Fl::event_key() == FL_Enter)
47-
{
48-
// get currently selected list item
49-
int curLine = app->hostList->value();
50-
51-
if (curLine > 0)
52-
{
53-
HostItem * itm = static_cast<HostItem *>(app->hostList->data(curLine));
54-
55-
if (itm != NULL)
56-
{
57-
itm->quickNote = app->quickNoteInput->value();
58-
app->quickNote->copy_label(itm->quickNote.c_str());
59-
app->quickNoteInput->value("");
60-
app->quickNoteWindow->hide();
61-
svConfigWrite();
62-
}
63-
}
64-
}
65-
return 1;
66-
}
67-
6843
static bool inMenu;
6944

7045
// handle child window input controls right-click
@@ -76,6 +51,9 @@ int SVInput::handle (int evt)
7651

7752
inMenu = true;
7853

54+
// TODO: Make *one* menu display function instead of copying code over and over
55+
// TODO: Pass (this) to it
56+
7957
// create context menu
8058
// text,shortcut,callback,user_data,flags,labeltype,labelfont,labelsize
8159
const Fl_Menu_Item miMain[] = {
@@ -173,6 +151,53 @@ int SVSecretInput::handle (int evt)
173151
}
174152

175153

154+
/* handle method for SVQuickNoteInput
155+
* (instance method)
156+
*/
157+
int SVQuickNoteInput::handle (int evt)
158+
{
159+
// save and close the quicknote editor
160+
if (evt == FL_KEYUP && app->quickNoteWindow != 0)
161+
{
162+
if (Fl::event_key() == FL_Enter)
163+
{
164+
// get currently selected list item
165+
int curLine = app->hostList->value();
166+
167+
if (curLine > 0)
168+
{
169+
HostItem * itm = static_cast<HostItem *>(app->hostList->data(curLine));
170+
171+
if (itm != NULL)
172+
{
173+
// set quickNote text
174+
itm->quickNote = std::string(app->quickNoteInput->value()).substr(0, 256);
175+
176+
if (itm->quickNote == "")
177+
{
178+
app->quickNote->textfont(FL_HELVETICA_ITALIC);
179+
app->quickNote->value("(no Quick Note)");
180+
}
181+
else
182+
{
183+
app->quickNote->textfont(FL_HELVETICA);
184+
app->quickNote->value(itm->quickNote.c_str());
185+
}
186+
187+
// clear the quickNote input and hide the quickNote input window
188+
app->quickNoteInput->value("");
189+
app->quickNoteWindow->hide();
190+
svConfigWrite();
191+
}
192+
}
193+
}
194+
return 1;
195+
}
196+
197+
return SVInput::handle(evt); //Fl_Input::handle(evt);
198+
}
199+
200+
176201
/* handle method for SVBox
177202
* (instance method)
178203
*/
@@ -191,7 +216,7 @@ int SVQuickNoteBox::handle (int evt)
191216

192217
Fl_Group * inputGroup = new Fl_Group(3, 3, 100, 24);
193218
inputGroup->box(FL_THIN_DOWN_BOX);
194-
app->quickNoteInput = new SVInput(0, 0, 100, 24);
219+
app->quickNoteInput = new SVQuickNoteInput(0, 0, 100, 24);
195220
inputGroup->end();
196221

197222
app->quickNoteWindow->end();
@@ -215,12 +240,16 @@ int SVQuickNoteBox::handle (int evt)
215240
app->quickNoteInput->size(app->quickNote->w(), app->quickNoteWindow->h());
216241
app->quickNoteInput->value(itm->quickNote.c_str());
217242

243+
// blank quickNote so user isn't confused by background text when editor displays
244+
app->quickNote->value("");
245+
218246
app->quickNoteWindow->show();
219247
}
220248
}
221249
}
222250

223-
return Fl_Box::handle(evt);
251+
//return Fl_Box::handle(evt);
252+
return Fl_Multiline_Output::handle(evt);
224253
}
225254

226255
/*
@@ -964,10 +993,13 @@ void svCreateGUI ()
964993

965994
// quicknote - very brief item info
966995
app->quickNote = new SVQuickNoteBox(0, 22, 100, 50);
967-
app->quickNote->labelsize(app->nAppFontSize);
996+
app->quickNote->textsize((app->nAppFontSize + 2));
997+
app->quickNote->textfont(FL_HELVETICA_ITALIC);
968998
app->quickNote->align(FL_ALIGN_TOP_LEFT | FL_ALIGN_INSIDE);
969999
app->quickNote->box(FL_THIN_DOWN_BOX);
970-
//// app->quickNote->labelfont(1);
1000+
app->quickNote->wrap(1);
1001+
app->quickNote->clear_visible_focus();
1002+
app->quickNote->value("(no Quick Note)");
9711003

9721004
app->quickNoteGroup->end();
9731005

@@ -1475,7 +1507,8 @@ void svHandleHostListEvents (Fl_Widget *, void *)
14751507
{
14761508
// set itm's quicknote text, if any
14771509
app->quickNoteLabel->label("");
1478-
app->quickNote->label("");
1510+
app->quickNote->textfont(FL_HELVETICA_ITALIC);
1511+
app->quickNote->value("(no Quick Note)");
14791512

14801513
return;
14811514
}
@@ -1486,7 +1519,17 @@ void svHandleHostListEvents (Fl_Widget *, void *)
14861519

14871520
// set itm's quicknote text, if any
14881521
app->quickNoteLabel->copy_label(itm->name.c_str());
1489-
app->quickNote->copy_label(itm->quickNote.c_str());
1522+
1523+
if (itm->quickNote == "")
1524+
{
1525+
app->quickNote->textfont(FL_HELVETICA_ITALIC);
1526+
app->quickNote->value("(no Quick Note)");
1527+
}
1528+
else
1529+
{
1530+
app->quickNote->textfont(FL_HELVETICA);
1531+
app->quickNote->value(itm->quickNote.c_str());
1532+
}
14901533

14911534
// *** DO *NOT* CHECK vnc FOR NULL HERE!!! ***
14921535
// *** IT'S OKAY IF vnc IS NULL AT THIS POINT!!! ***
@@ -2039,8 +2082,31 @@ void svHandleQuickNoteWindowEvents (Fl_Widget *, void *)
20392082
// window is closing
20402083
if (event == FL_LEAVE)
20412084
{
2042-
app->quickNoteInput->value("");
2043-
app->quickNoteWindow->hide();
2085+
int nHostItemNum = app->hostList->value();
2086+
HostItem * itm = static_cast<HostItem *>(app->hostList->data(nHostItemNum));
2087+
2088+
if (itm == NULL)
2089+
{
2090+
// set itm's quicknote text, if any
2091+
app->quickNoteLabel->label("");
2092+
app->quickNote->textfont(FL_HELVETICA_ITALIC);
2093+
app->quickNote->value("(no Quick Note)");
2094+
}
2095+
else
2096+
{
2097+
app->quickNoteInput->value("");
2098+
if (itm->quickNote == "")
2099+
{
2100+
app->quickNote->textfont(FL_HELVETICA_ITALIC);
2101+
app->quickNote->value("(no Quick Note)");
2102+
}
2103+
else
2104+
{
2105+
app->quickNote->textfont(FL_HELVETICA);
2106+
app->quickNote->value(itm->quickNote.c_str());
2107+
}
2108+
app->quickNoteWindow->hide();
2109+
}
20442110
}
20452111
}
20462112

src/app.h

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
#include <FL/Fl_Secret_Input.H>
5656
#include <FL/Fl_Spinner.H>
5757
//#include <FL/Fl_Text_Editor.H>
58+
#include <FL/Fl_Multiline_Output.H>
5859
#include <FL/Fl_Widget.H>
5960
#include <FL/Fl_Window.H>
6061

@@ -78,6 +79,7 @@
7879

7980

8081
class SVInput;
82+
class SVQuickNoteInput;
8183

8284
/* global app class */
8385
class AppVars
@@ -238,9 +240,9 @@ class AppVars
238240
std::string sshCommand;
239241
Fl_Group * quickNoteGroup;
240242
Fl_Box * quickNoteLabel;
241-
Fl_Box * quickNote;
243+
Fl_Multiline_Output * quickNote;
242244
Fl_Window * quickNoteWindow;
243-
SVInput * quickNoteInput;
245+
SVQuickNoteInput * quickNoteInput;
244246
} extern * app;
245247

246248

@@ -250,7 +252,7 @@ class SVInput : public Fl_Input
250252
public:
251253
SVInput (int x, int y, int w, int h, const char * label = 0) :
252254
Fl_Input(x, y, w, h, label) {}
253-
private:
255+
//private:
254256
int handle (int event);
255257
};
256258

@@ -265,11 +267,21 @@ class SVSecretInput : public Fl_Secret_Input
265267
};
266268

267269
/* subclassed box */
268-
class SVQuickNoteBox : public Fl_Box
270+
class SVQuickNoteBox : public Fl_Multiline_Output
269271
{
270272
public:
271273
SVQuickNoteBox (int x, int y, int w, int h, const char * label = 0) :
272-
Fl_Box(x, y, w, h, label) {}
274+
Fl_Multiline_Output(x, y, w, h, label) {}
275+
private:
276+
int handle (int event);
277+
};
278+
279+
/* subclassed input box */
280+
class SVQuickNoteInput : public SVInput
281+
{
282+
public:
283+
SVQuickNoteInput (int x, int y, int w, int h, const char * label = 0) :
284+
SVInput(x, y, w, h, label) {}
273285
private:
274286
int handle (int event);
275287
};

src/hostitem.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ class HostItem
8585
lastErrorMessage(""),
8686
sshWaitTime(5),
8787
sshCmdStream(NULL),
88-
sshCloseThread(0)
88+
sshCloseThread(0),
89+
quickNote("")
8990
{}
9091

9192
std::string name;

0 commit comments

Comments
 (0)