示例#1
0
PrefsDialog::PrefsDialog( Window *frame, Window *parent ) :
  Dialog( frame, parent, Strings::get( 168 ),
          AWindow::CENTER | AWindow::ISMODAL | AWindow::ADJUSTSIZE,
          0, 0, 500, 365 )
{
  char *namestr = "PrefsDialog";
  name = new char[strlen(namestr)+1];
  strcpy( name, namestr );

  getGraphics()->setDialogFont();

  int margin = 10, fontHeight = Graphics::dialogDesignFontHeight,
      yStart = getClientHeight() - fontHeight*2 - 20,
      interSpace = fontHeight + fontHeight / 2;

  prevUseBigFont = AGraphics::useBigFont;

  Notebook *notebook =
	  new Notebook( this, 0, 50, getClientWidth(), getClientHeight() - 50, 
		              Color::BKGR, 0 );

	asciiDialog = new AsciiDialog( notebook, notebook );
	ascii2Dialog = new Ascii2Dialog( notebook, notebook );
	hexDialog = new HexDialog( notebook, notebook );
	editorDialog = new EditorDialog( notebook, notebook );
	displayDialog = new DisplayDialog( notebook, notebook );
	miscDialog = new MiscDialog( notebook, notebook );

	notebook->add( editorDialog, Strings::get(188) );
	notebook->add( displayDialog, Strings::get(190) );
	notebook->add( asciiDialog, Strings::get(166) );
	notebook->add( ascii2Dialog, Strings::get(209) );
	notebook->add( hexDialog, Strings::get(179) );
	notebook->add( miscDialog, Strings::get(196) );

  OKButton = new Button( this, Strings::get(8), AWindow::ISDEFAULT|ISTABSTOP,
                             10, 10, 70, 30 );
  OKButton->setYMove( FOLLOW );

  cancelButton = new Button( this, Strings::get(9), ISTABSTOP, 90, 10, 70, 30 );
  cancelButton->setYMove( FOLLOW );

	setControlsVisible();
  notebook->setTab( 0 );

  OKButton->addButtonListener( this );
  cancelButton->addButtonListener( this );

  adjustForFontSize();

  // Save/restore window position

  initSize();

  int x = getX(), y = getY(), width = getWidth(), height = getHeight();
  WinProperties::retrieveProperty( name, x, y, width, height );

  setSize( width, height );
  center( x, y );
  setPos( x, y );
}
示例#2
0
int main() {
    Notebook my;

    my.export_notes("notebook");

    cout << "------------------\n"
        << "Select action:\n"
        << "1) Add note\n"
        << "2) Find note\n"
        << "3) Remove note\n"
        << "4) Show all notes\n"
        << "q) Close notebook\n"
        << "------------------\n";    


    char ans;
    
    ans = cin.get();
    while (((ans < '1') || (ans > '4')) && (ans != 'q')) {
        if (ans != '\n')
            while (cin.get() != '\n');
        cout << "Please, enter correct command: ";
        ans = cin.get();
    }
    while (cin.get() != '\n');
    
    while (tolower(ans) != 'q') {
        switch (ans) {
            case '1' : {
                char name[100] = {};
                cout << "Enter name: ";
                cin.getline(name, 99);
                char phone[100] = {};
                cout << "Enter phone: ";
                cin.getline(phone, 99);
                if (!my.find(name))
                    my.add(name, phone);
                else {
                    cout << "Note " << name << " is already exist, replace? [y/n]: ";
                    char ch;
                    ch = cin.get();
                    ch = tolower(ch);
                    if (ch != '\n')
                        while (cin.get() != '\n');
                    while (ch != 'y' && ch != 'n') {
                        cout << "Enter y or n: ";
                        ch = cin.get();
                        ch = tolower(ch);
                        if (ch != '\n')
                            while (cin.get() != '\n');
                    }

                    if (tolower(ch) == 'y')
                        my.add(name, phone);
                }
                break;
            }
            case '2' : {
                char name[100] = {};
                cout << "Enter name: ";
                cin.getline(name, 99);
                char const * res = my.find(name);
                if (res == nullptr)
                    cout << name << " not found\n";
                else
                    cout << name << ": " << res << endl;
                break;
            }
            case '3' : {
                char name[100] = {};
                cout << "Enter name: ";
                cin.getline(name, 99);
                if (!my.find(name))
                    cout << name << " not found\n";
                else {
                    cout << "Confirm removal " << name << " [y/n]: ";
                    char ch;
                    ch = cin.get();
                    ch = tolower(ch);
                    if (ch != '\n')
                        while (cin.get() != '\n');
                    while (ch != 'y' && ch != 'n') {
                        cout << "Enter y or n: ";
                        ch = cin.get();
                        ch = tolower(ch);
                        if (ch != '\n')
                            while (cin.get() != '\n');
                    }

                    if (tolower(ch) == 'y')
                        my.remove(name);
                    cout << "Removal " << name << " complete\n";
                }
                break;
            }
            case '4' :
                my.show_all();
        }

        cout << "\n------------------\n"
            << "Select action:\n"
            << "1) Add note\n"
            << "2) Find note\n"
            << "3) Remove note\n"
            << "4) Show all notes\n"
            << "q) Close notebook\n"
            << "------------------\n";

        ans = cin.get();
        while (((ans < '1') || (ans > '4')) && (ans != 'q')) {
            if (ans != '\n')
                while (cin.get() != '\n');
            cout << "Please, enter correct command: ";
            ans = cin.get();
        }
        while (cin.get() != '\n');
    }

    my.import_notes("notebook");

    return 0;
}