⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 iodlg.c

📁 SEAL是DOS 下的32位保护模式的GUI程序
💻 C
📖 第 1 页 / 共 4 页
字号:
  if ( event->type & EV_MESSAGE ) { /* message event */

      switch ( event->message ) {

         case MSG_OPENDIR : {

              if ( LISTBOX(o)->flags & FL_DIROPEN )  /* open directory, end modal */

                     event->message = MSG_OK; /* end modal */

         }; break;

         case MSG_OK  : { /* open file/directory */

            if ( o->is_state(o, OB_SF_FOCUSED) ) {

                 l_int what = FILELISTBOX(o)->file_handle(FILELISTBOX(o));

                 if ( what == 2 ) { /* selected is directory */

                     clear_event(event);

                 };

            } else if ( io_isext(FILELISTBOX(o)->file) ) { /* file is extension */

                    /* reload load list */

                    FILELISTBOX(o)->load_list(FILELISTBOX(o), FILELISTBOX(o)->path, FILELISTBOX(o)->file);

                    clear_event(event);

            };

            /* file is may-be file */

            if ( event->type ) {  /* event type wasn't clear => maybe file */

                  t_event  oldev = *event;
                  l_text   file = FILELISTBOX(o)->get_file(FILELISTBOX(o));
                  l_text   rf = io_realpath(FILELISTBOX(o)->path, file);

                  if ( LISTBOX(o)->flags & FL_OPEN ) { /* i'm open dialog */

                        if ( !io_isfile(rf) ) { /* no !, this file not exist */

                              /* make message, file not found */
                              msgbox(MW_ERROR, MB_OK, "%s %s %s.\n\n%s.", TXT_FILE, file, strlwr(TXT_NOTFOUND), TXT_CHECKTHEFILENAMEANDTRYAGAIN);

                              /* try again */
                              clear_event(&oldev);
                        };

                  } else
                  if ( LISTBOX(o)->flags & FL_SAVE ) { /* i'm save dialog */

                        if ( io_isfile(rf) ) { /* oh !, this file exist */

                              /* ask for rewriting */
                              if ( msgbox(MW_WARNING, MB_YES|MB_NO, "%s %s %s.\n\n%s ?", TXT_FILE, file, strlwr(TXT_EXIST), TXT_WOULDYOULIKETOOVERWRITEIT) != MSG_YES )

                                    /* button cancel, try again */
                                    clear_event(&oldev);
                        };

                  };

                  _free(rf);

                  *event = oldev;

            };

         }; break;

         case MSG_NEWDIRECTORY : { /* make new directory */

             clear_event(event);

             FILELISTBOX(o)->new_directory(FILELISTBOX(o));

         }; break;

         case MSG_CHANGENAME : { /* change name of file/directory */

             clear_event(event);

             FILELISTBOX(o)->change_name(FILELISTBOX(o));

         }; break;

         case MSG_PROPERTIES : { /* properties of file/directory */

            p_filelistbox_item rec = (p_filelistbox_item)LISTBOX_ITEM_AT(LISTBOX(o)->list, LISTBOX(o)->current);

            clear_event(event);

            if ( rec && rec->properties ) {

               l_text rn = io_realpath(rec->info.path, rec->info.filename); /* get real name of file = "path"/"filename" */

               if ( rec->properties(rn) ) /* something was changed */

                   /* reload list */

                   RETYPE_FILES_IN_PATH(FILELISTBOX(o)->path);


               _free(rn);

             };

         }; break;

      };

  };

};



/*
  if o->file is exension && filelistbox is focused
  then return name of selected item, else return o->file
*/
l_text filelistbox_get_file ( p_filelistbox o )
{

   if ( io_isext(FILELISTBOX(o)->file) ) /* is extension */

         return FILELISTBOX_ITEM_FILENAME(LISTBOX(o)->list, LISTBOX(o)->current);

   return FILELISTBOX(o)->file;

};


void   filelistbox_rewrite_item ( p_listbox o, l_long item )
{

   l_text   item_text = NULL;
   l_text   old_file;
   p_item   it = LISTBOX_ITEM_AT(LISTBOX(o)->list, LISTBOX(o)->current);
   t_event  e;

   listbox_rewrite_item(o, item); /* old call of listbox_rewrite_item */

   if ( !it ) return;

   old_file = (l_text)(((p_filelistbox_item)(it))->info.filename);

   it = LISTBOX_ITEM_AT(LISTBOX(o)->list, LISTBOX(o)->current);

   item_text = (l_text)(((p_filelistbox_item)(it))->info.filename);

   if ( !(o->flags & FL_DIROPEN) ) { /* not directory open */

         set_event(&e, EV_INFO, MSG_SELECTEDFILELISTBOXITEM, OBJECT(o));

         OBJECT(o)->put_event(OBJECT(o), &e);

         if ( old_file && item_text && !stricmp(old_file, item_text) ) { /* not same files */

               l_int attrib = ((p_filelistbox_item)(it))->info.attrib;

               if ( FA_ISFILE(attrib) && FILELISTBOX(o)->file_sel ) { /* new item is file && file_sel function exist */

                     l_text rf = io_realpath(FILELISTBOX(o)->path, item_text);

                     FILELISTBOX(o)->file_sel(rf); /* call file_sel function, when file is sel */

               };

         };

   };

};


/*
  make operations for specific attributes
*/

l_int   filelistbox_file_handle_ex ( p_filelistbox o, l_text opath, l_text ofile, l_int attrib, l_text filename )
{

      if ( !opath ) return 0;

      if ( attrib & FA_DIREC && filename ) { /* current is directory */

         if ( !strcmp(filename, "..") ) { /* parent dir !! filename must be tested if not NULL */

              l_text path = io_parentdir(opath);

              o->load_list(o, path, ofile);

              return 2;

         } else { /* sub directory */

            o->load_list(o, io_realpath(opath, filename), ofile);

            return 2;

        };


      };

  return 0;

};


l_int   filelistbox_file_handle ( p_filelistbox o )
{

  p_filelistbox_item item = LISTBOX_ITEM_AT(LISTBOX(o)->list, LISTBOX(o)->current);

  if ( item ) {

    l_int ok;

    ok = o->file_handle_ex(o, o->path, o->file, item->info.attrib, item->info.filename);

    return ok;

  };

  return 0;

};


l_dword filelistbox_file_menu ( p_filelistbox o )
{

  p_filelistbox_item item = NULL;

  item = LISTBOX_ITEM_AT(LISTBOX(o)->list, LISTBOX(o)->current);

  if ( item ) {

      l_int fatr = item->info.attrib;

      p_menu p = new_menu(

                 new_menu_item_ex(TXT_OPEN, NULL, 0, MSG_OK, true,
                                  TXT_INFOOPEN, MIF_NONE, font_system, NULL, NULL, 0,
                 new_menu_line(
                 new_menu_item(TXT_CHANGENAME, NULL, 0, MSG_CHANGENAME, TXT_INFOCHANGENAME,
                 new_menu_line(
                 new_menu_item(TXT_COPY, NULL, 0, MSG_COPY, TXT_INFOCOPY,
                 new_menu_item(TXT_DELETE, NULL, 0, MSG_CUT, TXT_INFODEL,
                 new_menu_item(TXT_PASTE, NULL, 0, MSG_PASTE, TXT_INFOPASTE,
                 new_menu_line(
                 new_menu_item(TXT_PROPERTIES, NULL, 0, MSG_PROPERTIES, TXT_INFOPROPERTIES,
                 new_menu_line(
                 new_sub_menu(TXT_NEW, new_menu(

                     new_menu_item(TXT_DIRECTORY, NULL, 0, MSG_NEWDIRECTORY, TXT_INFONEWDIRECTORY,
                     NULL)),

                NULL)))))))))))
             );

      if ( p ) {

         t_rect   r = rect_assign(mouse->where.x-5, mouse->where.y-5, 0, 0);

         p_object menu = OBJECT(menuview_init(
                                _malloc(sizeof(t_menuview)),
                                r,
                                p)
                         );


         return desktop->execute_view(desktop, VIEW(menu));

      };
  };

  return MSG_CANCEL;
};


/*
   make new directory
   return true directory was made, else return false
*/
l_bool  filelistbox_new_directory ( p_filelistbox o )
{
   l_bool ret = false;

   l_text ud = io_uniquedir(o->path); /* get unique dir */

   if ( ud ) {

       l_text rp = io_realpath(o->path, ud);
       l_text nd = NULL;

       if ( io_mkdir(rp) ) { /* unique name is ok */

            LISTBOX(o)->list->insert(LISTBOX(o)->list, new_filelistbox_item(ud, NULL, false, 0, FA_DIREC, 0, 0, 0, o->path, ud));

            LISTBOX(o)->rewrite_item(LISTBOX(o), LISTBOX(o)->get_max(LISTBOX(o)));

            if ( !o->change_name(o) ) /* wasn't reload list */

                    /* reload list */
                    RETYPE_FILES_IN_PATH(o->path);


            ret = true;
       };

       _free(rp);
       _free(ud);

   };

   return ret;
};


/*
   change name of current item
   return true if item name was changed, else return false
*/
l_bool  filelistbox_change_name ( p_filelistbox o )
{
   l_bool ret = false;

   if ( LISTBOX(o)->list ) {

      p_filelistbox_item item = LISTBOX_ITEM_AT(LISTBOX(o)->list, LISTBOX(o)->current);

      t_rect r = LISTBOX(o)->get_item_rect(LISTBOX(o), LISTBOX(o)->current); /* get current item rect */

      p_textline t = worktextline_init((p_textline)_malloc(sizeof(t_textline)),
                                       r,
                                       IO_DIR_LIMIT);
      if ( !t ) return NULL;

      if ( item )

            t->set_text(t, item->info.filename);

      OBJECT(o)->insert(OBJECT(o), OBJECT(t));


      if ( t && VIEW(o)->execute_view(VIEW(o), VIEW(t)) != MSG_CANCEL ) /* not ESC */

         if ( t->text ) { /* set name of item to new name */

               l_text oldname = io_realpath(item->info.path, item->info.filename);
               l_text newname = io_realpath(item->info.path, t->text);
               l_int  err = 0;

               err = io_rename(oldname, newname);

               if ( err > 0 ) { /* remove errors ! warning ! not renamed, my god, what's the matter ? > I'm really happy */
                    /* draw info about */
                    msgbox(MI_ERROR, MB_OK, "%s", TXT_FILECOULDNTBERENAME);

               } else if ( err == 0 ) { /* no error, then redraw */

                    _free(item->info.filename); /* free old name */
                    item->obclass.name = _strdup(t->text); /* set to new name */

                    RETYPE_FILES_IN_PATH(o->path);


                    ret = true;
               };

               _free(oldname);

               _free(newname);

         };

      dispose(OBJECT(t));

   };

   return ret;
};


/* reload file item list and redraw this listbox */

void  filelistbox_load_list ( p_filelistbox o, l_text path, l_text file )
{

  if ( path && file && io_exist(path) ) { /* path exist */

      l_text path_ex = _strdup(path);
      l_text file_ex = _strdup(file);

      LISTBOX(o)->shift_flag = 0;

      if ( path != o->path ) _free(path);
      if ( file != o->file ) _free(file);

      _free(o->path);
      _free(o->file);

      o->path = path_ex;
      o->file = file_ex;

      if ( o->path ) {
         dispose_list(&LISTBOX(o)->list, 1);

         LISTBOX(o)->list = get_listbox_item_dirfiles(path_ex, file_ex, o->attrib, icon_size(o));

         LISTBOX(o)->draw_box(LISTBOX(o));

         LISTBOX(o)->rewrite_item(LISTBOX(o), 0);

         draw_scroller_bars(SCROLLER(o));
      };

  } else seal_error(ERR_INFO, "%s %s %s", TXT_PATH, path, strlwr(TXT_NOTFOUND));
};



/* t_filehistory functions */

l_dword   filehistory_show_box ( p_history o )
{

  l_dword msg = history_show_box(o);

  if ( msg == MSG_OK && FILEHISTORY(o)->filebox ) { /* some item was pressed */

       l_text filename = FILELISTBOX_ITEM_FILENAME(o->list, o->current);

       FILEHISTORY(o)->filebox->load_list(FILEHISTORY(o)->filebox, FILEHISTORY(o)->filebox->path, _strdup(filename));

  };

  return msg;

};

/* t_filetextline functions */

void  filetextline_translate_event ( p_object o, p_event event )
{

  RETVIEW(o, event);


  textline_translate_event(o, event); /* old translate_event function */


  /* keyboard event */

  if ( event->type & EV_KEYBOARD && OBJECT(keyb)->state & KB_SF_KEYDOWN &&

       OBJECT(o)->is_state(OBJECT(o), OB_SF_FOCUSED) ) {

       if ( keyb->code == TO_KEY(KB_ENTER) ) { /* enter was pressed */

          clear_event(event);

          set_event(event, EV_MESSAGE, MSG_OK, o); /* call MSG_OK2 */

       };

  };

  if ( event->type & EV_MESSAGE ) /* event message */

     if ( event->message == MSG_OK && o->is_state(o, OB_SF_FOCUSED) ) {

         if ( TEXTLINE(o)->text && FILETEXTLINE(o)->filebox ) {  /*  */

               FILETEXTLINE(o)->filebox->file = TEXTLINE(o)->text;

               if ( io_isext(FILETEXTLINE(o)->filebox->file) ) {

                     clear_event(event);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -